Commit Graph

533 Commits

Author SHA1 Message Date
David Ungar
c7be2def90 Merge pull request #27143 from davidungar/A-9-12-eager-off
[NFC NameLookup ASTScope] Fixes for large app, eager primary tree creation, memberCount fix.
2019-09-14 18:46:17 -07:00
David Ungar
1c07cee1f4 Update scope_map_top_level.swift test 2019-09-14 13:56:28 -07:00
Pavel Yaskevich
260a482e1e [Diagnostics] NFC: Adjust some binary operator checks to verify exact diagnostic location
If one of the arguments to binary operator is invalid, let's
verify that diagnostic points directly to it.
2019-09-13 22:35:53 -07:00
Pavel Yaskevich
a1643d94f7 [Diagnostics] NFC: Update all of the improved test-cases 2019-09-13 22:35:52 -07:00
David Ungar
968c5a8282 Eager tree building for primaries 2019-09-13 17:22:50 -07:00
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
Slava Pestov
053c3c7d90 AST: New implementation of lookupInModule() that uses the ImportCache
Now that the normal name lookup shadowing can handle the module-based
shadowing rules implemented by lookupInModule(), we can drastically
simplify the implementation, replacing the graph traversal with an
iteration over the linearized graph.
2019-08-29 15:56:32 -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
David Ungar
2ae2006346 Fix test 2019-08-28 13:47:47 -07:00
David Ungar
7992e1c6c4 Lots of cleanups, renamings, etc. 2019-08-26 16:55:18 -07:00
Slava Pestov
52131531e5 Sema: Catch invalid stored properties in the StorageImplInfoRequest
Previously we were only checking in declarations in primary files, which
is insufficient since SILGen crashes if presented with an invalid stored
property.

Fixes <rdar://problem/54471229>, <https://bugs.swift.org/browse/SR-11322>.
2019-08-20 14:47:52 -04: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
Saleem Abdulrasool
33be0c8043 test: adjust for Windows tests
Adjust the path separator for Windows.  Should repair the tests on
Windows.
2019-08-15 09:57:10 -07:00
David Ungar
b02b4b00ef Cleanup and fixes, also 1st cut at lazy. 2019-08-13 17:48:06 -07:00
David Ungar
9d6b665dee Require assertions on scope-printing tests 2019-08-08 13:32:07 -07:00
Saleem Abdulrasool
cd57bb4cf2 tests: repair the test suite after 3a2d284 2019-08-08 08:06:19 -07:00
David Ungar
3a2d284d5d Merge pull request #26535 from davidungar/A-7-9-astscope-no-nesting-off
[NameLookup ASTScope] Latest experimental ASTScope code, off by default.
2019-08-07 19:02:09 -07:00
David Ungar
4bf3cf349c Fix the test 2019-08-07 16:00:37 -07:00
David Ungar
f336eec948 Merge pull request #26531 from davidungar/print-which-lookup
Add frontend flag `-warn-if-astscope-lookup` with test
2019-08-07 13:09:11 -07:00
David Ungar
09342dfa47 Add frontend flag -warn-if-astscope-lookup w/ test 2019-08-06 23:17:49 -07:00
David Ungar
f64033a2d2 Manual rebase with master 2019-08-06 22:13:20 -07:00
Slava Pestov
2ef101c815 Sema: Don't add local functions to TC.definedFunctions
Instead, check them and their error handling right away.

In addition to fixing the crash in the radar, this also causes
us to emit unused variable warnings in functions containing
local functions.

Eventually, TC.definedFunctions should go away altogether.

Fixes <rdar://problem/53956342>.
2019-08-07 00:37:21 -04:00
Pavel Yaskevich
2cfcdf49dc Merge pull request #26391 from sl/port-tuple-assignment-diagnostic
[Diagnostics] Ported tuple mismatch diagnostic to new diagnostic framework
2019-08-02 13:22:52 -07:00
Sam Lazarus
a3b56c2790 Diagnostics: Ported tuple mismatch diagnostic to new diagnostic framework 2019-07-29 13:45:08 -04:00
Doug Gregor
fe2a57979b [Test] Fix indentation 2019-07-16 21:18:00 -07:00
Doug Gregor
f173124c0c Merge pull request #26174 from DougGregor/property-wrappers-ambig-53164203
[Name lookup] Deduplicate nominal declarations found via resolveTypeDeclsToNominal
2019-07-16 21:07:46 -07: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
Jordan Rose
123399db2b Treat "lookup into immediately imported modules" as a special case
Features like `@testable import` change the results produced by name
lookup in the source file with the testable import. What they
/shouldn't/ do is change the results of lookup into the same module
from elsewhere in the import graph...and neither should cached results
from lookup elsewhere in the import graph affect the lookups from the
source file. Encode this difference in the cache used during
module-level name lookup to fix testable imports like this.

(The test case here looks a little contrived because of '@_exported',
but that's how imports are treated in Clang modules and with bridging
headers, so it is in fact a realistic scenario.)

rdar://problem/48890959
2019-07-09 10:36:49 -07:00
Pavel Yaskevich
84a6103128 Merge pull request #25844 from xedin/diagnose-instance-method-on-metatype
[Diagnostics] Diagnose all invalid references to instance methods
2019-07-01 00:33:54 -07:00
Saleem Abdulrasool
4d75156f14 test: fix path separator 2019-06-28 08:13:52 -07:00
Slava Pestov
7434e37605 Sema: Fix crash with circular property initial values
Fixes <rdar://45313700>, <https://bugs.swift.org/browse/SR-9015>.
2019-06-27 23:13:46 -04:00
Slava Pestov
4dc891db5a Sema: Tweak VarDecl validation circularity break
Fixes <rdar://problem/51266778>.

We don't need to set the VarDecl's validation state when we go to
validate the PatternBindingDecl, since the PatternBindingDecl
already has its own circularity check.
2019-06-27 23:13:45 -04:00
David Ungar
723b3911d7 fix typo 2019-06-27 17:44:15 -07:00
Pavel Yaskevich
c118c383d8 [Diagnostics] Diagnose all invalid references to instance methods
Extend use of "instance member on type" fix to cover potentially
invalid partial applications, references to instance members on
metatypes, and remove related and now obsolete code from `CSDiag`.

Resolves: [SR-9415](https://bugs.swift.org/browse/SR-9415)
2019-06-27 16:09:07 -07:00
David Ungar
2b093fac30 Fixed scope_map.swift tests. 2019-06-23 21:10:37 -07:00
Saleem Abdulrasool
ec73c3bdae test: make NameBinding.scope_map* pass on Windows
Loosen the test from over-fitting for path separator.
2019-06-15 10:40:44 -07:00
David Ungar
2d0a8f2c6a Passes either way 2019-06-10 20:25:57 -07:00
David Ungar
6b6c983594 Fix scope test 2019-06-10 19:47:58 -07:00
David Ungar
6cdb14719a Printing tweaks 2019-06-10 18:06:44 -07:00
David Ungar
2b63173f63 Fixed scope test 2019-06-10 15:59:47 -07:00
David Ungar
e7cd5344f5 Fixed test 2019-06-10 15:47:42 -07:00
David Ungar
614f1cd0ff Fixed test 2019-06-05 15:16:04 -07:00
David Ungar
fc4cc211f7 Fixed test 2019-06-05 14:47:09 -07:00
David Ungar
663760e3b7 ASTOOScope ontology 2019-05-28 10:48:22 -07:00
Slava Pestov
7566f98a45 Sema: Diagnose enum inheritance clause containing subclass existential
Also, tidy up the code a bit and stop emitting redundant diagnostics for
associated types.

Fixes <https://bugs.swift.org/browse/SR-10232>.
2019-04-01 22:41:16 -04:00
Jordan Rose
0ba6c495ba Add @_implementationOnly
This is an attribute that gets put on an import in library FooKit to
keep it from being a requirement to import FooKit. It's not checked at
all, meaning that in this form it is up to the author of FooKit to
make sure nothing in its API or ABI depends on the implementation-only
dependency. There's also no debugging support here (debugging FooKit
/should/ import the implementation-only dependency if it's present).

The goal is to get to a point where it /can/ be checked, i.e. FooKit
developers are prevented from writing code that would rely on FooKit's
implementation-only dependency being present when compiling clients of
FooKit. But right now it's not.

rdar://problem/48985979
2019-03-28 15:57:53 -07:00
Pavel Yaskevich
688042becf [Diagnostics] Add inaccessible member diagnostic 2019-03-18 13:48:08 -07:00
Pavel Yaskevich
42e0f21409 [CSDiagnostics] Improve requirement failure source detection
If affected declaration is a static or instance memeber (excluding
operators) and failed requirement is declared in other nominal type
or extension, diagnose such problems as `in reference` instead of
claiming that requirement belongs to the member itself.
2019-02-08 15:05:42 -08:00
Pavel Yaskevich
6fd1600534 [ConstraintSystem] Diagnose conditional requirement failures via fixes
Extend existing `RequirementFailure` functionality to support
conditional requirement failures. Such fixes are introduced
only if the parent type requirement has been matched successfully.

Resolves: rdar://problem/47871590
2019-02-08 11:16:54 -08:00
Doug Gregor
18f4bcb5ff [Name lookup] Implement name shadowing rule for Data.withUnsafeBytes.
Address an annoying source compatibility issue with the introduction
of Data.withUnsafeBytes, which is ambiguous with Swift NIO's
implementatio of the same function. Do so with a narrow hackish name
shadowing rule (the Swift NIO version shadows the Foundation version)
that we will eventually generalize to something sensible.

Fixes rdar://problem/46850346.
2019-01-23 16:45:08 -08:00