Commit Graph

1007 Commits

Author SHA1 Message Date
David Ungar
7631ae9148 Manual format correction and added TODOs 2019-02-17 22:35:48 -07:00
David Ungar
13176ff4cf Format 2019-02-17 21:53:42 -07:00
David Ungar
65967171de Move factory method bodies out. 2019-02-17 21:53:14 -07:00
David Ungar
97602a9829 Broke up finishLookup 2019-02-17 14:00:15 -07:00
David Ungar
ca025ab8cf First cut no mutable isCascadingUse 2019-02-17 13:14:55 -07:00
David Ungar
92faaae093 constification 2019-02-17 00:16:18 -07:00
David Ungar
2fd4e2d9de Format 2019-02-17 00:12:11 -07:00
David Ungar
b02b682766 Eliminating mutable DC 2019-02-17 00:11:49 -07:00
David Ungar
977b0db93d Nonfmt cut down on DC 2019-02-16 23:35:25 -07:00
David Ungar
3c295f8228 Group lookupDecls etc into PlacesToSearch 2019-02-16 22:43:10 -07:00
David Ungar
79906debe2 Factor isOutsideBodyOfFunction 2019-02-16 21:07:02 -07:00
David Ungar
ee3c2eea81 Don’t use DC 2019-02-16 21:05:45 -07:00
David Ungar
65ed915fc7 Factor lookupDecl handing 2019-02-16 13:05:10 -07:00
David Ungar
dbb998f189 better names 2019-02-16 12:24:53 -07:00
David Ungar
ee40bfbdba Note factoring possibility 2019-02-16 12:22:30 -07:00
David Ungar
ebd8b38350 Factor GenericParameterCheck 2019-02-16 12:19:16 -07:00
David Ungar
8ece21459b Push GenericParamList check into function case. 2019-02-16 11:55:41 -07:00
David Ungar
3b7131cf0b Factor each variant into a separate function. Facter out Decl dispatch. 2019-02-16 11:49:07 -07:00
David Ungar
e9298a1ee0 Renamed shouldReturnBasedOnResults to isFinishedWithLookupNowThatIsAboutToLookForOuterResults 2019-02-16 11:34:43 -07:00
David Ungar
04ef0daeb8 Add ExpUnqualifiedLookup, cross-check 2019-02-16 11:31:16 -07: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
Slava Pestov
4681b9b1e4 AST: Break circularity in qualified lookup into protocol or extension with 'Self' constraints 2019-01-18 15:12:41 -05:00
Slava Pestov
acb37b2b55 AST: Set ClassDecl's HasDestructor bit in one place 2019-01-18 00:15:41 -05:00
Pavel Yaskevich
ddc2fa415e [AST] NFC: introduce ASTContext::isAccessControlDisabled 2019-01-11 17:30:10 -08:00
Parker Schuh
f5859ff46e Rename NameAliasType to TypeAliasType. 2019-01-09 16:47:13 -08:00
Doug Gregor
a2a663c9a9 [Name lookup] Narrow shadowing to non-member types.
Narrow the recently-introduced shadowing rule for types so that it only
applies to non-member types. Member types lack a reasonable syntax for
specifying precisely which module to look into, and there are a few use
cases where the type checker will pick a type that would be shadowed by
the new rule.

Fixes a source-compatibility regression introduced by the shadowing rule.
2018-12-17 09:57:32 -08:00
Doug Gregor
9f61301855 [Name lookup] Enable shadowing for type lookup and of the Swift module.
Tweak the shadowing rules in two ways:

1) For unqualified type lookup, apply shadowing rules. Without this, we
would always get an ambiguity if there were two types with the same name,
so this should be a strict improvement.
2) Allow a name introduced in any other module to shadow a name in the
Swift standard library. This is (another) weak form of a more sensible,
generalized rule that would use the import graph to describe shadowing.

Together, these tweaks allow the Result type that was recently introduced in
the standard library to exist without breaking source compatibility for
Swift code that is already using a Result type. The user Result type will
shadow (hide) the Swift one. The latter can be spelled Swift.Result if it
is needed by such code.

Fixes rdar://problem/46767892.
2018-12-16 22:12:48 -08:00
Slava Pestov
544e0a02d5 AST: Don't link together GenericParamLists of nested generic types
GenericParamList::OuterParameters would mirror the nesting structure
of generic DeclContexts. This resulted in redundant code and caused
unnecessary complications for extensions and protocols, whose
GenericParamLists are constructed after parse time.

Instead, lets only use OuterParameters to link together the multiple
parameter lists of a single extension, or parameter lists in SIL
functions.
2018-12-11 23:55:41 -05:00
Argyrios Kyrtzidis
fd3e79b27c [AST] In NameLookup.cpp avoid wrapping functions in namespaces 2018-12-07 09:45:40 -08:00
Argyrios Kyrtzidis
75ab0a5f36 [AST] Break dependency cycle between swiftAST and swiftSema
AST/LookupVisibleDecls.cpp has a dependency on swiftSema by having doGlobalExtensionLookup call into swift::isExtensionApplied,
and doGlobalExtensionLookup is ultimately used by the other global functions in that file.
Break the cycle by moving the file into the swiftSema library.
2018-12-06 22:52:38 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Brent Royal-Gordon
9bd1a26089 Implementation for SE-0228: Fix ExpressibleByStringInterpolation (#20214)
* [CodeCompletion] Restrict ancestor search to brace

This change allows ExprParentFinder to restrict certain searches for parents to just AST nodes within the nearest surrounding BraceStmt. In the string interpolation rework, BraceStmts can appear in new places in the AST; this keeps code completion from looking at irrelevant context.

NFC in this commit, but keeps code completion from crashing once TapExpr is introduced.

* Remove test relying on ExpressibleByStringInterpolation being deprecated

Since soon enough, it won’t be anymore.

* [AST] Introduce TapExpr

TapExpr allows a block of code to to be inserted between two expressions, accessing and potentially mutating the result of its subexpression before giving it to its parent expression. It’s roughly equivalent to this function:

  func _tap<T>(_ value: T, do body: (inout T) throws -> Void) rethrows -> T {
    var copy = value
    try body(&copy)
    return copy
  }

Except that it doesn’t use a closure, so no variables are captured and no call frame is (even notionally) added.

This commit does not include tests because nothing in it actually uses TapExpr yet. It will be used by string interpolation.

* SE-0228: Fix ExpressibleByStringInterpolation

This is the bulk of the implementation of the string interpolation rework. It includes a redesigned AST node, new parsing logic, new constraints and post-typechecking code generation, and new standard library types and members.

* [Sema] Rip out typeCheckExpressionShallow()

With new string interpolation in place, it is no longer used by anything in the compiler.

* [Sema] Diagnose invalid StringInterpolationProtocols

StringInterpolationProtocol informally requires conforming types to provide at least one method with the base name “appendInterpolation” with no (or a discardable) return value and visibility at least as broad as the conforming type’s. This change diagnoses an error when a conforming type does not have a method that meets those criteria.

* [Stdlib] Fix map(String.init) source break

Some users, including some in the source compatibility suite, accidentally used init(stringInterpolationSegment:) by writing code like `map(String.init)`. Now that these intializers have been removed, the remaining initializers often end up tying during overload resolution. This change adds several overloads of `String.init(describing:)` which will break these ties in cases where the compiler previously selected `String.init(stringInterpolationSegment:)`.

* [Sema] Make callWitness() take non-mutable arrays

It doesn’t actually need to mutate them.

* [Stdlib] Improve floating-point interpolation performance

This change avoids constructing a String when interpolating a Float, Double, or Float80. Instead, we write the characters to a fixed-size buffer and then append them directly to the string’s storage.

This seems to improve performance for all three types, but especially for Double and Float80, which cannot always fit into a small string when stringified.

* [NameLookup] Improve MemberLookupTable invalidation

In rare cases usually involving generated code, an overload added by an extension in the middle of a file would not be visible below it if the type had lazy members and the same base name had already been referenced above the extension. This change essentially dirties a type’s member lookup table whenever an extension is added to it, ensuring the entries in it will be updated.

This change also includes some debugging improvements for NameLookup.

* [SILOptimizer] XFAIL dead object removal failure

The DeadObjectRemoval pass in SILOptimizer does not currently remove reworked string interpolations as well as the old design because their effects cannot be described by @_effects(readonly). That causes a test failure on Linux. This change temporarily silences that test. The SILOptimizer issue has been filed as SR-9008.

* Confess string interpolation’s source stability sins

* [Parser] Parse empty interpolations

Previously, the parser had an odd asymmetry which caused the same function to accept foo(), but reject “\()”. This change fixes the issue.

Already tested by test/Parse/try.swift, which uses this construct in one of its throwing interpolation tests.

* [Sema] Fix batch-mode-only lazy var bug

The temporary variable used by string interpolation needs to be recontextualized when it’s inserted into a synthesized getter. Fixes a compilation failure in Alamofire.

I’ll probably follow up on this bug a bit more after merging.
2018-11-02 19:16:03 -07:00
Doug Gregor
feb1b55de2 [Name lookup] Look through parentheses when finding type references.
When resolving type declarations in, e.g., the inherited type declarations
request, look through parenthesized types. Fixes rdar://problem/45527696.
2018-10-24 14:02:24 -07:00
Slava Pestov
4ef1904e88 AST: Don't allow declarations to shadow generic parameters
Associated type inference can synthesize type aliases with the same name
as a generic parameter. This is all fine since the underlying type of
the alias is the generic parameter type, however it might have been
synthesized in a constrained extension, resulting in bogus diagnostics
that depend on the order in which declarations are type checked, which
can vary between WMO and non-WMO, different batch mode settings, etc.

Instead, let's just check the generic parameter list first.

Fixes <rdar://problem/22587551>, <rdar://problem/44777661>.
2018-10-15 19:24:27 -07:00
Slava Pestov
64f12ff936 Sema: Allow protocols with 'Self' constraints again
These two declarations are now equivalent:

  protocol P : SomeClass { ... }
  protocol P where Self : SomeClass { ... }

There's a long, complicated story here:

- Swift 4.2 rejected classes in the inheritance clause of a
  protocol, but it accepted the 'where' clause form, even
  though it didn't always work and would sometimes crash

- Recently we got the inheritance clause form working, and
  added a diagnostic to ban the 'where' clause form, because
  we thought it would simplify name lookup to not have to
  consider the 'where' clause

- However, we already had to support looking at the 'where'
  clause from name lookup anyway, because you could write

  extension P where Self : SomeClass { ... }

- It turns out that despite the crashes, protocols with
  'Self' constraints were already common enough that it was
  worth supporting the existing behavior, instead of banning
  it

Fixes <rdar://problem/43028442>.
2018-10-12 03:06:52 -07:00
Slava Pestov
36c8d94238 AST: Refactor SelfBoundsFromWhereClause to support ProtocolDecls 2018-10-12 03:06:52 -07:00
Slava Pestov
673e167fac AST: Refactor lookupQualified() to take a vector of NominalTypeDecls
Previously you could pass in a vector of TypeDecls and it handled
module and AnyObject lookup for you. The AnyObject case was never
used and the module was was only needed in one place, so clean
things up to make them more direct here.
2018-10-12 03:06:52 -07:00
Slava Pestov
8c7b924adf AST: Factor out populateLookupDeclsFromContext() 2018-10-12 03:06:52 -07:00
Slava Pestov
cd3f385468 AST: Use named lazy member loading to find constructors in deserialized types
Only imported types require the exception here.
2018-09-28 18:08:37 -07:00
Graydon Hoare
14db5d2285 [AST] Add and use NominalTypeDecl::LookupDirectFlags rather than booleans. 2018-09-21 14:34:26 -07:00
Graydon Hoare
eb15743657 [SR-8081] Teach full name-lookup codepaths about @_implements. 2018-09-21 14:34:26 -07:00
Doug Gregor
32fd274f5e Merge pull request #19391 from DougGregor/assoc-conformance-default-witnesses
[ABI] Associated conformance defaults
2018-09-19 13:15:46 -07:00
Doug Gregor
12da7c6e0e [SIL Parser] Extend the hack for Self in default witness tables.
We *still* need a better way to model this, eventually, but this keeps
the SIL parser limping along for default witness tables.
2018-09-19 10:57:28 -07:00
Slava Pestov
ef82cd760c Sema: Merge bindExtensionDecl() into validateExtension() 2018-09-19 09:47:36 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Doug Gregor
ac37747c78 [Type checker] Break isObjC/getObjCSelector cycle.
When we're marking a declaration as @objc and recording it in the
class and source-file lookup tables (for @objc collision detection),
don't cause a cycle by querying `getObjCSelector()`. This is somewhat
of a hack: a better long-term approach would be to move the recording
much later, and request'ify the name computation. That'll be follow-up
work.
2018-09-10 17:30:17 -07:00
Doug Gregor
1bc6b749a4 [Name lookup] Eliminate unnecessary, cyclic check for extended nominal type.
We weren’t getting anything out of the check for the extended nominal
declaration of an extension within unqualified name lookup except
some spurious cycles in the request-evaluator. Stop doing this.
2018-09-10 17:30:17 -07:00
Slava Pestov
8801aa67d3 Merge pull request #19133 from slavapestov/access-level-cleanup
Access level cleanup
2018-09-06 16:46:40 -07:00
Doug Gregor
cffe3869a6 Merge pull request #19034 from DougGregor/protocol-override
Introduce overrides of protocol members and drop them from witness tables
2018-09-05 20:57:21 -07:00
Slava Pestov
cdadee8173 AST: Fix layering violations in DefaultAndMaxAccessLevelRequest
Our walk over the requirement interface types meant that
computing the access level of an extension member depended
on type resolution and the GSB.

Fix this by adding a new request that simply collects all
TypeDecls referenced from a TypeRepr, and compute the
extension's maximum access level using that.

If we use Structural rather than Interface type resolution when
walking the extension's requirements, we don't have to build its
generic signature first.
2018-09-05 16:18:54 -07:00