Commit Graph

1018 Commits

Author SHA1 Message Date
Slava Pestov
445d747622 AST: Move GenericParamList and friends to GenericParamList.{h,cpp} 2020-09-29 19:51:03 -04:00
Brent Royal-Gordon
806125d6f8 Favor private imports during name lookup
Private imports are intended to make the file performing the import more or less source-compatible with the file being imported from, so that code from the original file can be modified by relatively simple syntactic transformations. However, their name shadowing behavior was very different from the original file. In the original file, other declarations in the same module would have shadowed declarations imported from any other module; in a file using a @_private import, they would all be considered imports, and thus all would be preferred equally. This could cause ambiguity in a file using a @_private import that was not present in the original file.

This commit changes that behavior by favoring @_private imports over other imports, so that if a name is visible through both a private and a non-private import, the one visible through the private import will shadow the other. This shadowing takes a higher priority than a scoped import, but a lower priority than the check for whether one of the modules is only visible through the other.

Fixes rdar://68312053.
2020-09-23 14:04:17 -07:00
Robert Widmann
d93c6d8b12 Remove Cascading Computations from ASTScope 2020-09-21 10:42:33 -06:00
Robert Widmann
7bee5ffc0c Remove NLOptions::NL_Known* 2020-09-21 10:37:41 -06:00
Robert Widmann
259e1a94c9 Remove UnqualifiedLookupFlags::KnownPrivate 2020-09-21 10:37:41 -06:00
Slava Pestov
cfffb40601 AST: Perform a top-level lookup in directReferencesForUnqualifiedTypeLookup() if necessary
UnqualifiedLookupRequest takes a DeclContext and a SourceLoc. If the
SourceLoc is valid, it locates the innermost ASTScope containing this
location, and starts the lookup from that scope.

Also, ASTScope currently walks up the scope tree to find the
innermost scope that corresponds to the given DeclContext, in case
the DeclContext is a parent of the 'natural' DeclContext for this
source location.

We want to remove this additional behavior and make ASTScope only
depend on a source file and source location.

This requires changing directReferencesForUnqualifiedTypeLookup()
to handle the top-level lookup case explicitly. See the comment for
more details.
2020-09-16 20:07:58 -04:00
Brent Royal-Gordon
cff4ddf13a [NFC] Adopt new ImportPath types and terminology
# Conflicts:
#	lib/IDE/CodeCompletion.cpp
2020-09-10 19:07:49 -07:00
Suyash Srijan
172c4be02d [Sema] Diagnose use of ambiguous property wrappers (#33688) 2020-08-29 02:38:42 +01:00
Slava Pestov
9ea0741587 Sema: Carefully tweak shadowing rules
TypeChecker::lookupMemberType() performs a lookup on the base type,
and disambiguates multiple results by filtering out result decls
that have canonically equal types under the base type substitution.

I'd like to refactor conformance checking to call lookupQualified()
directly and bypass lookupMemberType(), but this requires adding a
new shadowing rule to primitive name lookup to simulate the effect
of the type-based disambiguation.

We already had a shadowing rule which states that concrete type
members shadow protocol members of the same name, but this was
bypassed for member _types_. This change generalizes this rule to
apply to member types also.

Hopefully this doesn't break source compatibility in practice.
2020-08-18 02:00:20 -04:00
Anthony Latsis
792da10925 Revert "Sema: Make type resolution for EnumElementPattern less eager" 2020-08-10 16:02:28 +03:00
Anthony Latsis
337501eb7e Merge pull request #33227 from AnthonyLatsis/unbound-thinout-1
Sema: Make type resolution for EnumElementPattern less eager
2020-08-01 16:14:14 +03:00
Slava Pestov
94c6bff65d AST: Replace some calls to getDeclaredType() with getDeclaredInterfaceType() 2020-07-31 13:39:01 -04:00
Anthony Latsis
9462de1f30 Sema: Make type resolution for EnumElementPattern less eager 2020-07-31 15:26:00 +03:00
Slava Pestov
c46eb22fcd AST: Don't attach trailing where clause requirements to the GenericParamList
Previously we had two representations for the 'where' clause of a
parsed declaration; if the declaration had generic parameters of
its own, we would store them in the GenericParamList, otherwise
we would store them separately in a TrailingWhereClause instance.

Since the latter is more general and also used for protocols and
extensions, let's just use it for everything and simplify
GenericParamList in the process.
2020-07-28 02:07:16 -04:00
Slava Pestov
a39c560e7b AST: Remove redundant cloneGenericParams() helper function 2020-07-28 02:07:16 -04:00
Slava Pestov
43e37b7895 AST: Move GenericParamListRequest::evaluate() to NameLookup.cpp 2020-07-28 02:07:16 -04:00
Robert Widmann
ec885b027b [NFC] const-qualify Inheritance-Clause-Bearing PointerUnion 2020-07-23 20:45:24 -07:00
Michael Gottesman
092edd6621 [ast] Rename VarPattern -> BindingPattern.
VarPattern is today used to implement both 'let' and 'var' pattern bindings, so
today is already misleading. The reason why the name Var was chosen was done b/c
it is meant to represent a pattern that performs 'variable binding'. Given that
I am going to add a new 'inout' pattern binding to this, it makes sense to
give it now a better fitting name before I make things more confusing.
2020-07-16 18:56:01 -07:00
Hamish Knight
4b1ffa5314 [NameLookup] Ensure extensions are updated after module load
Call prepareExtensions to make sure we load in any
new extensions brought in by modules loaded
after-the-fact. This isn't an issue for normal
compilations as we load all the modules up-front
in import resolution, but clients such as the
LLDB REPL may load in modules later.

Resolves rdar://64040436.
2020-06-15 12:01:04 -07:00
Robert Widmann
b8d0cf342c [NFC] Only Resolve TypeReprs If Given a RequirementRepr
Resolve the written type instead of the semantic type since that's the only data these requests will have access to once RequirementRepr is made completely syntactic.
2020-06-11 16:18:23 -07:00
Robert Widmann
29cdbe87f1 Strip TypeEraserAttr of its TypeLoc 2020-06-10 19:33:31 -07:00
Robert Widmann
fb8fdd9644 Replace resolveCustomAttrType with a Request 2020-06-10 19:31:41 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Slava Pestov
6ca148d65e AST: Optimize removeShadowedDecls()
Previously, whenever name lookup returned two declarations with the same
name, we would compute the canonical type of each one as part of the
shadowing check.

The canonical type calculation is rather expensive for GenericFunctionTypes
since it requires constructing a GenericSignatureBuilder to canonicalize
type parameters that appear in the function's signature.

Instead, let's first shard all declarations that have the same name by
their generic signature. If two declarations have the same signature, only
then do we proceed to compute their canonical type.

Since computing a canonical GenericSignature is cheaper than computing a
canonical GenericFunctionType, this should speed up name lookup of
heavily-overloaded names, such as operators.

Fixes <rdar://problem/56800097>.
2020-05-26 23:49:14 -04:00
Hamish Knight
9e2cdf49b3 Merge pull request #31506 from hamishknight/hello-operator 2020-05-23 09:48:21 -07:00
Robert Widmann
4eb5689115 Merge pull request #31960 from CodaFi/your-references-are-off-the-chain
Delete ReferencedNameTracker
2020-05-22 20:44:37 -07:00
Hamish Knight
05d377dc24 Make ObjCSelector's lookupDirect return a TinyPtrVector
Returning a MutableArrayRef caused us to
accidentally mutate the lookup table when
re-arranging decls for diagnostics.
2020-05-21 21:10:36 -07:00
Robert Widmann
acbf927b0e [NFC] Delete ReferencedNameTracker 2020-05-21 18:54:14 -07:00
Hamish Knight
917c937fc9 Allow shadowing checks to deal with operator decls
Add overloads of `removeShadowedDecls` that deal
with operator and precedencegroup decls, and
template the existing shadowing logic such that it
can process them.
2020-05-18 14:33:41 -07:00
Daniel Sweeney
ea526c6383 Converting ModuleDecl::ImportedModule from std::pair to a dedicated struct. (#31360) 2020-04-30 20:26:03 -07:00
Varun Gandhi
65577940d0 [NFC] Get rid of -Wrange-loop-analysis warnings. (#31324) 2020-04-27 09:47:52 -07:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Robert Widmann
94166024fa Dump all uses of the legacy referenced name tracker 2020-04-20 10:22:58 -07:00
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
Robert Widmann
42cfc7eb58 Add "Legacy" to the manual referenced name tracker 2020-03-31 16:16:53 -07:00
Robert Widmann
8c69814f5c Define Dependency Sinks
Convert most of the name lookup requests and a few other ancillary typechecking requests into dependency sinks.

Some requests are also combined sinks and sources in order to emulate the current scheme, which performs scope changes based on lookup flags. This is generally undesirable, since it means those requests cannot immediately be generalized to a purely context-based scheme because they depend on some client-provided entropy source. In particular, the few callers that are providing the "known private" name lookup flag need to be converted to perform lookups in the appropriate private context.

Clients that are passing "no known dependency" are currently considered universally incorrect and are outside the scope of the compatibility guarantees. This means that request-based dependency tracking registers strictly more edges than manual dependency tracking. It also means that once we fixup the clients that are passing "known private", we can completely remove these name lookup flags.

Finally, some tests had to change to accomodate the new scheme. Currently, we go out of our way to register a dependency edge for extensions that declare protocol conformances. However, we were also asserting in at least one test that extensions without protocol conformances weren't registering dependency edges. This is blatantly incorrect and has been undone now that the request-based scheme is automatically registering this edge.
2020-03-31 16:16:53 -07:00
Robert Widmann
987cd55f50 [NFC] Drop llvm::Expected from Evaluation Points
A request is intended to be a pure function of its inputs. That function could, in theory, fail. In practice, there were basically no requests taking advantage of this ability - the few that were using it to explicitly detect cycles can just return reasonable defaults instead of forwarding the error on up the stack.

This is because cycles are checked by *the Evaluator*, and are unwound by the Evaluator.

Therefore, restore the idea that the evaluate functions are themselves pure, but keep the idea that *evaluation* of those requests may fail. This model enables the best of both worlds: we not only keep the evaluator flexible enough to handle future use cases like cancellation and diagnostic invalidation, but also request-based dependencies using the values computed at the evaluation points. These aforementioned use cases would use the llvm::Expected interface and the regular evaluation-point interface respectively.
2020-03-26 23:08:02 -07:00
Robert Widmann
302b7f5bf9 [NFC] Define InheritedProtocolsRequest
Refactor the interface to ProtocolDecl::getInheritedProtocols in
preparation for request-based dependency tracking.
2020-03-23 18:49:23 -07:00
Robert Widmann
59106636bf [Gardening] Remove unused ASTContext variable 2020-03-20 12:14:48 -07:00
Robert Widmann
7abbe701ff Merge pull request #30522 from CodaFi/skeleton-key
[NFC] Don't Mutate Flags; Just Read ASTContext::isAccessControlDisabled
2020-03-20 01:09:42 -07:00
Robert Widmann
31cfab854a [NFC] Don't Mutate Flags; Just Read ASTContext::isAccessControlDisabled
Make configureLookup a little easier to reason about by pushing the read
of this flag down into lookup instead of mutating the lookup flags
beforehand.
2020-03-19 18:05:10 -07:00
Robert Widmann
6d60d01420 [NFC] Remove the Legacy Semantic Queries Bit
Clients that wish to avoid semantic requests should decline to register
those requests.
2020-03-19 11:04:12 -07:00
Robert Widmann
70b6bbcb13 Remove swift::createTypeChecker
Replace it with the "legacy semantic queries" bit. The remaining client
of this bit is SourceKit, which appears to require this bit be set
conditionally so certain semantic property wrapper requests return
a sentinel value.

We should migrate these requests to a syntactic interface as soon as
possible.

rdar://60516325
2020-03-16 19:20:22 -07:00
Robert Widmann
c3c490efb0 Remove the ability to reference instances of TypeChecker 2020-03-16 19:19:02 -07:00
Robert Widmann
92b8d637f1 [Sema] Always install property wrappers during qualified lookup
Revert the property wrappers part of dd51251014.

Every part of the qualified lookup stack needs to synthesize property
wrapper members, otherwise we'll be subject to the relativistic effects
of semantic lookups in different files. Besides, Codable was the main
source of cycles and circularity under the old scheme.

Resolves rdar://59531889
2020-02-19 14:23:07 -08:00
Slava Pestov
0b502d8c84 AST: loadNamedMembers() never fails
This allows us to simplify lookupDirect() a fair bit as well.
2020-02-12 18:32:46 -05:00
Robert Widmann
d1823ebec8 [NFC] Make prepareLookupTable lazier about loading Extension members
Use the same laziest-possible extension member loading path for
everything.
2020-01-25 11:04:53 -08:00
Robert Widmann
e626cfb378 Remove lazy member loading re-entrancy guards
Effectively revert #28907. The request evaluator will also catch re-entrancy here, and those cycles can be broken with NameLookupFlags::IgnoreNewExtensions.
2020-01-25 11:04:53 -08:00
Robert Widmann
b09c9957ad Reintroduce NameLookupFlags::IgnoreNewExtensions
Soft revert a09382c. It should now be safe to add this flag back as an optimization to specifically disable lazy member loading instead of all extension loading.

Push the flag back everywhere it was needed, but also push it into lookup for associated type members which will never appear in extensions.
2020-01-25 11:04:53 -08:00
Robert Widmann
26d8bad7c2 Add DirectLookupRequest 2020-01-25 11:04:53 -08:00