Commit Graph

418 Commits

Author SHA1 Message Date
Owen Voorhees
43e2d107e1 [SE-0276] Implement multi-pattern catch clauses
Like switch cases, a catch clause may now include a comma-
separated list of patterns. The body will be executed if any
one of those patterns is matched.

This patch replaces `CatchStmt` with `CaseStmt` as the children
of `DoCatchStmt` in the AST. This necessitates a number of changes
throughout the compiler, including:
- Parser & libsyntax support for the new syntax and AST structure
- Typechecking of multi-pattern catches, including those which
  contain bindings.
- SILGen support
- Code completion updates
- Profiler updates
- Name lookup changes
2020-04-04 09:28:26 -07:00
Hamish Knight
8ec634e787 [ASTVerifier] NFC: Remove verifyBound
This isn't used for anything.
2020-03-29 18:43:58 -07:00
Nathan Hawes
77daaf3338 [ASTVerifier] Don't perform semantic requests in verifyParsed()
SourceKit doesn't install a typechecker for its syntactic requests so was
hitting assertions in these methods if any typechecking was triggered.
2019-11-15 18:10:22 -08:00
Robert Widmann
01d272073a Requestify Witness Resolution
Witness matching is a source of a lot of ad-hoc cycles, and mixes the
logic that performs resolution, caching, validation, and cycle detection into one
place.  To make matters worse, some checkers kick off other checks in
order to cache work for further declarations, and access an internal
cache on their subject conformance for many requirements at once, or
sometimes just one requirement.

None of this fits into the request evaluator's central view of the
caching.  This is further evidenced by the fact that if you attempt to
move the caching step into the evaluator, it overcaches the same
witness and trips asserts.

As a start, define requests for the resolution steps, and flush some
hacks around forcing witness resolution. The caching logic is mostly
untouched (the requests don't actually cache anything), but some cycle
breaking is now handled in the evaluator itself.  Once witness matching
has been refactored to cache with the evaluator, all of these hacks can
go away.

My urge to destroy the LazyResolver outweighs the compromises here.
2019-11-05 13:28:07 -08:00
Slava Pestov
dad642c9da Merge pull request #28040 from slavapestov/dont-force-the-issue
Don't unnecessarily force InterfaceTypeRequest
2019-11-04 18:27:30 -05:00
Slava Pestov
3b7a0b24f5 AST: Remove some unnecessary (void) getInterfaceType() calls 2019-11-04 14:59:01 -05:00
Robert Widmann
3b8f3b53be Remove a double-checked invariant
Now that isInvalid() is a semantic property, drop the assertion for this
invariant in the ASTVerifier.  This should also remove the last client
that wasn't registering the lazy resolver and expecting to pull any old
interface type out, so change a hack to an assertion to hopefully catch
future callers before we remove the LazyResolver entirely.
2019-11-04 11:44:11 -08:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
Robert Widmann
3b829943af Uniformly iterate over the pattern binding entry indices
Clarify a bunch of C-style for loops and remove a ton of references to getPatternList().
2019-10-17 13:39:07 -07:00
Robert Widmann
56b6e53dae Remove raw references to PatternBindingEntry APIs
Switch most callers to explicit indices.  The exceptions lie in things that needs to manipulate the parsed output directly including the Parser and components of the ASTScope.  These are included as friend class exceptions.
2019-10-17 13:31:14 -07:00
Slava Pestov
6bfe518344 AST: Compute FuncDecl::isStatic() using a request 2019-10-07 22:20:18 -04:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
Jordan Rose
8ff1dac381 [AST] Break some header dependencies for faster rebuilds (#27374)
DiagnosticEngine.h no longer depends on Attr.h.
Expr.h no longer depends on TypeRepr.h.

No functionality change.
2019-09-26 09:17:10 -07:00
Robert Widmann
b135928125 Drop CheckingWithValidSignature from the validation state machine
Now that the generic signature is computable on demand, this predicate is doubly useless.  All of the callers intended to ask "hasInterfaceType" anyways.
2019-09-20 22:22:49 -07:00
Slava Pestov
9a454d4fe8 AST: Clean up ASTVerifier's archetype verification a bit 2019-09-20 17:59:56 -04:00
Jordan Rose
8d7f1b7c5d [AST] Separate SourceFile from FileUnit.h
Like the last commit, SourceFile is used a lot by Parse and Sema, but
less so by the ClangImporter and (de)Serialization. Split it out to
cut down on recompilation times when something changes.

This commit does /not/ split the implementation of SourceFile out of
Module.cpp, which is where most of it lives. That might also be a
reasonable change, but the reason I was reluctant to is because a
number of SourceFile members correspond to the entry points in
ModuleDecl. Someone else can pick this up later if they decide it's a
good idea.

No functionality change.
2019-09-17 17:54:41 -07:00
Jordan Rose
853caa66d4 [AST] Split FileUnit and its subclasses out of Module.h
Most of AST, Parse, and Sema deal with FileUnits regularly, but SIL
and IRGen certainly don't. Split FileUnit out into its own header to
cut down on recompilation times when something changes.

No functionality change.
2019-09-17 17:54:41 -07:00
Robert Widmann
d68f1259d7 Teach the ASTVerifier not to force generic signatures
The ASTVerifier is called by parsing tests and IDE tests that may not necessarily set up a typechecker.  Remove the verifier's ability to force computing generic signatures so we don't accidentally wander into the typechecker and crash.
2019-09-16 11:41:53 -07:00
Slava Pestov
e027c82f37 ASTVerifier: Simpler archetype verification 2019-09-06 17:16:04 -04:00
Slava Pestov
e9bcd00bc2 AST: Remove GenericEnvironment::OwningDC 2019-09-06 17:16:03 -04:00
David Ungar
72b1e27c7d Merge pull request #26768 from davidungar/A-8-21-parserPR
[Parser, NameLookup, ASTScope] Parser changes for lazy ASTScopes
2019-08-23 13:46:11 -07:00
David Ungar
a40b694801 Use token start locations 2019-08-21 22:36:15 -07:00
Jordan Rose
da94834d1d Revert "ASTVerifier: make sure isFinal and FinalAttr are in sync (#26740)"
This reverts commit 387e0d68d3.
2019-08-21 11:42:51 -07:00
David Ungar
0dbf7e6ab6 Parser changes for lazy ASTScopes 2019-08-21 09:45:45 -07:00
Jordan Rose
387e0d68d3 ASTVerifier: make sure isFinal and FinalAttr are in sync (#26740)
Serialization is currently working around them /not/ having been in
sync in the past, but they are now, and we might as well start
depending on it.
2019-08-20 16:20:16 -07:00
Slava Pestov
62f18a52c0 Sema: Move attribute checking to typeCheckDecl() 2019-08-20 14:47:52 -04:00
Slava Pestov
1c3ac86796 AST: Banish OptionalTypeKind to ClangImporter.h
The only place this was used in Decl.h was the failability kind of a
constructor.

I decided to replace this with a boolean isFailable() bit. Now that
we have isImplicitlyUnwrappedOptional(), it seems to make more sense
to not have ConstructorDecl represent redundant information which
might not be internally consistent.

Most callers of getFailability() actually only care if the result is
failable or not; the few callers that care about it being IUO can
check isImplicitlyUnwrappedOptional() as well.
2019-08-15 18:41:42 -04:00
Slava Pestov
19d283d9dc AST: Replace ImplicitlyUnwrappedOptionalAttr with Decl::{is,set}ImplicitlyUnwrappedOptional() 2019-08-15 18:41:41 -04:00
Slava Pestov
94149db4ec Parse: Record which delayed type and extension bodies possibly contain operators and classes
To properly delay parsing type and extension bodies we need to know
which ones might contain nested operator and class definitions, since
they must be known upfront when building the global operator lookup
and AnyObject dispatch lookup tables, respectively.

To guess if the type contains operator definitions, we look for the
'func' keyword followed by an operator token.

To guess if the type contains class definitions, we look for the
'class' keyword.

For now, this information is recorded but not used. Subsequent commits
will make use of this information to delay parsing in more cases.
2019-08-12 17:15:51 -04:00
Slava Pestov
0063f158be AST: Request-ify synthesis of the implicit destructor 2019-08-09 19:08:47 -04:00
David Ungar
f64033a2d2 Manual rebase with master 2019-08-06 22:13:20 -07:00
David Ungar
e3d6e6b844 Merge pull request #26416 from davidungar/pbd-sourcerange
[ASTScope lookup] Fix PatternBindingEntry initializer getters and rectify its source range
2019-08-05 14:48:47 -07:00
Slava Pestov
0c5d52d860 AST: Introduce AbstractStorageDecl::get{Parsed,Opaque}Accessor()
Also, change visitOpaqueAccessors() to call getOpaqueAccessor() instead of
asserting if the expected accessor does not exist.
2019-08-02 19:34:43 -04:00
Slava Pestov
64c32c695b AST: Remove a few utility methods from AbstractStorageDecl
Since the return value of getAccessor() depends on mutable state, it
does not make sense in the request evaluator world. Let's begin by
removing some utility methods derived from getAccessor(), replacing
calls to them with calls to getAccessor().
2019-08-01 18:31:58 -04:00
David Ungar
6a9b199302 Add source range order test for Decls only
Failing tests: test/SourceKit/CursorInfo/cursor_info_property_wrappers.swift and test/decl/var/property_wrappers.swift
2019-07-28 10:09:44 -07:00
Jordan Rose
3596df7e12 Print attributes on enum cases correctly (like 'indirect') (#26311)
Previously they were just skipped if enum elements weren't exploded
into their own individual lines, since the ASTPrinter assumed they'd
be present on the EnumCaseDecl. This led to miscompiles when using
a module interface for an enum with indirect cases, since they'd be
printed as non-indirect cases.

rdar://problem/53329452
2019-07-23 19:48:02 -07:00
Slava Pestov
a532a325e1 AST: Move a few methods from VarDecl down to ParamDecl 2019-07-22 20:19:09 -04:00
pschuh
26c4cccb4b Convert InterpolatedStringLiteralExpr to not use tc.callWitness(). (#26076)
For reference, all other callers of callWitness have been migrated.
2019-07-16 10:24:45 -07:00
Slava Pestov
15a831614e Sema: Remove finalizeAbstractStorageDecl()
Also since we're lazier about validating accessors now, relax some
checks in the ASTVerifier so that it can tolerate implicit accessors
without interface types. All other declarations must still have
interface types in verifyChecked().

ASTVerifier: Tolerate implicit accessors without interface types
2019-07-11 20:55:42 -04:00
Slava Pestov
4c499fd4ac AST: Stop passing around LazyResolvers in various places 2019-07-06 00:43:22 -04:00
Parker Schuh
687ff25157 Convert ForEachStmt to not use tc.callWitness().
For reference, everything else except string interpolation has been converted
not to call this method.
2019-06-28 14:20:42 -07:00
Joe Groff
a419754fe9 Support nested types on opaque archetypes (and maybe opened ones). 2019-04-17 14:43:32 -07:00
Joe Groff
f008019bda Sema: Infer the underlying type for opaque return types from function bodies. 2019-04-17 14:43:32 -07:00
Slava Pestov
91dffc9d44 Sema: Use AnyFunctionType::printParams() to print argument lists instead of printing a tuple type
Once the '@escaping' bit is removed from TupleTypeElt, it no longer makes
sense to print argument lists as if they were TupleTypes or ParenTypes,
since function types are '@escaping' by default inside tuples but not
in argument lists.

Instead, print ArrayRef<AnyFunctionType::Param> directly. For now this
introduces some awkward usages of AnyFunctionType::decomposeInput();
these will go away once the AST is changed to represent the argument list
as a list of expressions and not a single tuple expression.
2019-04-15 00:22:29 -04:00
Sam Lazarus
3a089ccc24 Merge branch 'master' into slazarus/allow-access-through-existential-metatype 2019-04-05 16:33:33 -04:00
Sam Lazarus
dc27e4672d Sema: Restored AST verification but loosened the check
The check now passes if the type meets isExistentialType rather than isAnyExistentialType.
2019-04-05 16:33:12 -04:00
Sam Lazarus
a3f9586794 AST: Remove restriction preventing the base of a member reference from being an existential type 2019-04-05 16:33:01 -04:00
Michael Gottesman
7b0d8455ca [ast][silgen] Wire up the case body var decls and use them in SILGenPattern emission to fix the evil fallthrough bug.
rdar://47467128
2019-04-03 23:51:06 -07:00
Slava Pestov
6bb36b5c01 Sema: Subscript default arguments
Fixes <https://bugs.swift.org/browse/SR-6118>.
2019-04-02 20:37:01 -04:00
Slava Pestov
1467f554f5 AST: Remove ArgumentShuffleExpr 2019-03-31 01:36:19 -04:00