Commit Graph

1018 Commits

Author SHA1 Message Date
Slava Pestov
52479cadd5 AST: Fix source break with new shadowing rules
My recent refactoring of top-level lookup replaced the old
shadowing done as part of top-level lookup with two separate
rules:

- If all paths from the current source file to a module 'B'
  go through a module 'A', then declarations in 'A' shadow
  declarations in 'B'.

- If a declaration in module 'A' was found via a scoped
  import and a declaration with the same name in module 'B'
  was found via an unscoped import, prefer the declaration
  from module 'A'.

However this caused a source break when you have a scenario
like the following:

- A source file imports 'A', 'B', and 'B.Foo'.

- 'A' re-exports 'B'.

- Both 'A' and 'B' define a type named 'Foo'.

The problem is that the scoped import 'B.Foo' can actually
find both 'A.Foo' and 'B.Foo', since 'B' re-exports 'A'.

Furthermore, since the source file explicitly imports 'A',
'B' does not shadow 'A' in the import graph.

As a result neither shadowing rule would eliminate the
ambiguity.

The new rule combines the scoped import check and the
shadowing check by considering all access paths to 'A'
that are not shadowed by 'B'. Using this rule, 'A.Foo'
is only seen via the access path 'A', whereas 'B.Foo'
is seen under both 'B' and 'B.Foo'. Since 'B.Foo' is seen
via a scoped import and 'A.Foo' is only seen via an
unscoped import, we can conclude that 'B.Foo' shadows
'A.Foo'.

Fixes <rdar://problem/55205050>.
2019-09-12 21:30:43 -04:00
Robert Widmann
2161fd3778 Fix the declcontext used to find the extended nominal type
This should not start searching at the extension.  Start looking one
level up.  Breaks a potential cycle where an extension's generic
parameters were subject to lookup while computing the nominal type.
2019-09-06 17:22:31 -07:00
swift-ci
e011c67631 Merge pull request #27059 from CodaFi/find-my-friends 2019-09-06 12:33:53 -07:00
Robert Widmann
c25e21840a Convert some TypeLoc computations to helpers
These aren't requirements of the (Simple)Request interface.  Downgrade
them to helper functions.
2019-09-06 11:16:17 -07:00
Varun Gandhi
f2f63882e2 [NFC] Always use syntactic information in ExtendedNominalRequest.
Since we started saving the nominal in the .swiftmodule, changing the other
call-sites in ClangImporter to save the value means that we can rely on
the typeRepr being non-null except when the syntax tree was ill-formed.
2019-09-05 15:33:02 -07:00
Varun Gandhi
0dcb936531 Serialize extended nominal separately when serializing an extension.
Instead of computing it from the extended type after deserialization --
which is tricky to do, due to potential presence of protocol
compositions -- we obtain the extended nominal directly.

Fixes SR-11227 and linked rdar://problem/53712389.
2019-09-05 15:33:02 -07:00
Slava Pestov
a09382ce2b AST: Completely remove NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions 2019-09-03 22:53:52 -04:00
Slava Pestov
3196b5e1ac AST: If lazy member loading fails in an extension, don't revert the type to eager loading
We can just load all members of the extension and proceed.
2019-09-03 22:53:52 -04:00
Slava Pestov
220bc64064 ClangImporter: Directly track constructors imported into a nominal type
This avoids a re-entrant lookup while doing lazy member loading,
and eliminates a usage of LookupDirectFlags::IgnoreNewExtensions,
and the last usage of NominalTypeDecl::makeMemberVisible().
2019-09-03 22:39:36 -04:00
Slava Pestov
7f6ef1e12d AST: Don't visit all extensions of a type when doing lazy member lookup
Instead only do it while preparing the lookup table.
2019-09-03 22:39:35 -04:00
Suyash Srijan
d2198294f8 Merge pull request #26795 from theblixguy/fix/SR-11288
[Typechecker] Check conforming protocols of context when resolving a custom attribute
2019-08-30 20:22:33 +01:00
Slava Pestov
af309026b9 Merge pull request #26865 from slavapestov/faster-module-name-lookup
Faster module name lookup
2019-08-29 19:46:05 -04:00
Doug Gregor
2c9def8e74 Merge pull request #26925 from DougGregor/parse-members-request
[Parser] Introduce a request for parsing type and extension members.
2019-08-29 13:56:33 -07:00
Slava Pestov
2256b1fcc2 AST: Introduce namelookup::getAllImports() to replace forAllVisibleModules() 2019-08-29 15:57:38 -04:00
Doug Gregor
d8f7c9e72c [Parser] Introduce a request for parsing type and extension members.
Ensure that lazy parsing of the members of nominal type definitions
and extensions is handled through a request. Most of the effort here
is in establishing a new request zone for parser requests.
2019-08-28 21:39:56 -07:00
Slava Pestov
37f308b8d3 AST: Change lookupInModule() to take a DeclContext instead of a module and extra imports
Also get rid of the 'accessPath' parameter.
2019-08-28 21:09:23 -04:00
Slava Pestov
61a4a48e21 AST: Add scoped import shadowing rule to removeShadowedDecls()
This simulates the shadowing done by ModuleNameLookup, which is about to be
removed.

The basic idea is that top-level declarations found via scoped imports
take precedence over unscoped imports.
2019-08-28 20:54:22 -04:00
Slava Pestov
f567b8ff42 AST: Use new module shadowing rule for qualified lookups too 2019-08-28 20:54:22 -04:00
Slava Pestov
1c28684441 AST: Add module visibility shadowing rule to removeShadowedDecls()
This simulates the shadowing done by ModuleNameLookup, which is about to be
removed.

The basic idea is that if a module A imports a module B, and B imports C,
then from A's point of view, top-level declarations from B will shadow
top-level declarations from C.
2019-08-28 16:29:50 -04:00
Slava Pestov
962f358e68 AST: Don't compute overload signature unless needed in removeShadowedDecls() 2019-08-28 16:29:50 -04:00
Slava Pestov
dcefd7f085 AST: Qualified lookup doesn't need to prune duplicate results 2019-08-28 16:29:50 -04:00
Slava Pestov
665cff1172 AST: Use ImportCache to simplify DeclContext::lookupQualified() 2019-08-28 16:29:50 -04:00
Slava Pestov
b3d95d7968 AST: removeShadowedDecls() takes a DeclContext instead of a ModuleDecl
This allows shadowing rules to depend on the current SourceFile and
not just the current ModuleDecl. For now, this isn't actually
taken advantage of.
2019-08-28 15:41:03 -04:00
Suyash Srijan
094869555e Merge branch 'master' into fix/SR-11288 2019-08-28 02:27:44 +01:00
Robert Widmann
8d22702a22 Use Integrated Caching
Replumb the TypeLoc for the extended type as a TypeRepr instead. Fixup
the myriad callsites this touches in the process.
2019-08-26 11:48:29 -07:00
Slava Pestov
9e18f2a1fe AST: Use ResolutionKind::TypesOnly for qualified lookup too 2019-08-24 22:35:51 -04:00
Slava Pestov
d13353f43a AST: Split off ModuleNameLookup.h from NameLookup.h 2019-08-23 23:35:25 -04:00
Suyash Srijan
357c7ef11b [AST] CustomAttrNominalRequest should look into protocol members as well
When performing unqualified lookup via directReferencesForUnqualifiedTypeLookup(), we should look into protocol members as well, as it's possible that the user has defined a typealias
2019-08-22 23:40:20 +01:00
Slava Pestov
80ccbe5116 AST: Stop passing around a LazyResolver in name lookup
Note that in all cases it was either nullptr or ctx.getLazyResolver().
While passing in nullptr might appear at first glance to mean something
("don't type check anything"), in practice we would check for a nullptr
value and pull out ctx.getLazyResolver() instead. Furthermore, with
the lazy resolver going away (at least for resolveDeclSignature() calls),
it won't make sense to do that anymore anyway.
2019-08-19 23:00:57 -04:00
Slava Pestov
94c5a35bf2 AST: Add some counters related to name lookup 2019-08-19 23:00:57 -04:00
Slava Pestov
bbdc7ae8e5 AST: Force parsing unparsed extensions of lazy-member (deserialized or imported) nominals
There was a bit of a misunderstanding between the 'lazy member' code
and the 'delayed member parsing' code. We have to explicitly parse
extensions of a 'lazy member' type when incrementally building the
lookup table, otherwise we'll never revisit the parsed extension
members later.

No test case because this can't happen right now; we force all delayed
parsing before any qualified lookups are performed. However everything
breaks badly without this change once delayed member parsing actually
occurs.
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
Doug Gregor
4b1fff980d [Name lookup] Deduplicate nominal declarations found via resolveTypeDeclsToNominal.
Perform basic deduplication of the nominal type declarations found via
resolveTypeDeclsToNominal(). Fixes rdar://problem/53164203
2019-07-16 16:54:55 -07:00
Slava Pestov
4c499fd4ac AST: Stop passing around LazyResolvers in various places 2019-07-06 00:43:22 -04:00
Harlan Haskins
d23101d337 [Sema] Compute superclass of deserialized protocols via generic signature
We don't need to serialize the protocol's superclass, we can compute it from the
generic signature. Previously, we would drop the superclass while
serializing because we didn't check the generic signature in
SuperclassTypeRequest, which would cause us to cache `NULL` when we
called `setSuperclass` for a protocol with a superclass constraint.

Fixes rdar://50526401
2019-06-18 16:38:09 -07:00
David Ungar
663760e3b7 ASTOOScope ontology 2019-05-28 10:48:22 -07:00
Ben Langmuir
34da079aa6 Pass DynamicLookupInfo through VisibleDeclConsumers NFC
This commit adds a new type DynamicLookupInfo that provides information
about how a dynamic member lookup found a particular Decl. This is
needed to correctly handle KeyPath dynamic member lookups, but for now
just plumb it through everywhere.
2019-05-06 10:02:39 -07:00
Slava Pestov
07ce01d96d AST: Replace ASTContext's ObjCMethodConflicts list with a per-SourceFile list 2019-04-22 20:42:08 -04:00
Slava Pestov
e97fc4e0c2 AST: Replace ASTContext's ObjCMethods list with a per-SourceFile list 2019-04-22 20:42:07 -04:00
Joe Groff
5e1497967a Parse opaque types. 2019-04-17 14:43:32 -07:00
Gogul Balakrishnan
1fa3846224 Add more hooks for overriding name lookup in the DebuggerClient (#23031) 2019-04-08 15:19:31 -07:00
Michael Gottesman
564b4fc11a [silgenpattern] Fix some stack-use-after-free errors caused by iterating over an Optional<ArrayRef<T>>.
Specifically the bad pattern was:

```
   for (auto *vd : *caseStmt->getCaseBodyVariables()) { ... }
```

The problem is that the optional is not lifetime extended over the for loop. To
work around this, I changed the API of CaseStmt's getCaseBodyVariable methods to
never return the inner Optional<MutableArrayRef<T>>. Now we have the following 3
methods (ignoring const differences):

1. CaseStmt::hasCaseBodyVariables().

2. CaseStmt::getCaseBodyVariables(). Asserts if the case body variable array was
   never specified.

3. CaseStmt::getCaseBodyVariablesOrEmptyArray(). Returns either the case body
   variables array or an empty array if we were never given any case body
   variable array.

This should prevent anyone else in the future from hitting this type of bug.

radar://49609717
2019-04-04 13:34:36 -07: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
Doug Gregor
a848d12665 Parse unknown attributes as "custom" attributes.
Parse custom attributes with the grammar:

```
'@' type-identifier expr-paren?
```
2019-03-29 23:10:36 -07:00
Doug Gregor
9e5d8ee222 Merge pull request #22977 from DougGregor/constraint-solver-common-result-type
[Constraint solver] Compute common apply result type in the solver.
2019-02-28 23:48:17 -08:00
Doug Gregor
0ea6536b95 [Name shadowing] Extend Objective-C initializer shadowing to imported inits.
There are multiple ways in which the Clang importer can produce an
initializer, and we have existing name shadowing rules to decide on
the best. Extend those rules to cover the case where a
Clang-importer-synthesized initializer collides with a C function
imported as an initializer. There's technically no reason to do the
latter because the former already exists, but some frameworks
currently depend on this.

Prior to this, the constraint solver was preferring the synthesized
initializer already (which is the right thing to do), for the wrong
reasons.
2019-02-28 09:13:32 -08:00
David Ungar
6982e66ddf Refactor filterForDiscriminator and call of addLocalVariableResults. 2019-02-22 12:41:03 -07:00
David Ungar
5d49b3bb3d Minor cleanumps 2019-02-20 14:41:23 -07:00
David Ungar
cd48cd6eb3 Format 2019-02-20 14:35:52 -07:00
David Ungar
1595efe5e2 Split the file, unfmt 2019-02-20 14:34:11 -07:00