Resolve the exceptions @throws names in the type checker
Why
Review on #9198: exception analysis compares exceptions by name, and a library's @throws(E) reached callers as the bare name E, while a catch was spelled Lib.E. So a correct catch was still reported, and a caller's own E could hide the library's. Reanalyze cannot resolve the names itself, because a .cmt keeps no environments.
The type checker now gives every exception an identity and resolves the names in a @throws where they are written: - When it types an exception, it records the identity, the unit and module path (Lib.Inner.F), in a generated @res.exn attribute on the definition. A rebound exception (exception Mine = Lib.E) carries the identity of the one it rebinds. - For a @throws on an external, a let in a signature or interface, or any let binding, it looks each name up and adds a generated @res.throws listing each exception's name and identity. The inferred signature keeps it next to @throws. - A name that is not an exception in scope gets the new warning 113 and is listed as written; lowercase names, which are never exceptions, do not warn. The first exception of that name counts, so a variant constructor declared later does not hide it. A payload may be one name, as a constructor or a string (also a template), or an array, tuple or list{...} of names, in braces or not. - Depend counts the modules a @throws names as dependencies, since the type checker loads them.
Exception analysis compares those identities with the constructors that catches and throws use. A call's exceptions are the declaration's resolved @throws, or, when it has none, the implementation binding's: the declaration is what callers see. Messages name an exception as the code they are about would, relative to its enclosing module.
Known limits: an identity belongs to a declaration, and a signature's exception E is a different declaration from the definition it hides. So when only an implementation sealed by a module type annotates its @throws, callers' catches of the module's E do not match it, and modules sealed by one module type share its exceptions' identities. The exceptions of two applications of one functor share an identity, and so do same-named exceptions of a functor's parameter and body, or of a local module and its enclosing module. A @throws(X.E) for an exception that a functor parameter's module type declares keeps that declaration's identity.
modifiedReanalyze exceptions of other modules
// ThrowsLibExn.resexception E@throws(E)external parse: string => int = "parseThrowing" // ThrowsLibExnCalls.reslet catchExternal = s => try ThrowsLibExn.parse(s) catch { | ThrowsLibExn.E => 0 }exception Elet catchUnrelatedLocal = s => try ThrowsLibExn.parse(s) catch { | E => 0 }
reanalyze Exception Analysis
ThrowsLibExnCalls.res:4:5-17ThrowsRepoCalls.res:29:5-20ThrowsScopes.res:2:5-18ThrowsLibExnCalls.res:42:5-23addedDiagnostic warning 113
@throws(Missing)let f = () => 1
diagnostic
Warning number 113throws_unbound_warning.res:3:9-15 @throws names Missing, which is not an exception in scope here. Exception analysis cannot match it with the exceptions callers catch.
Review
- Why identities in the type checker, not in reanalyze? Only the type checker knows which exception a name means. Two attempts to rebuild the scope in reanalyze kept missing opens in interfaces, includes, functors and aliases.