Commit Graph

974 Commits

Author SHA1 Message Date
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
David Ungar
80a234a2ef Use a struct instead of a pair 2019-02-20 11:08:06 -07:00
David Ungar
e9277469fb Unify two cases 2019-02-20 10:38:55 -07:00
David Ungar
1ce86b9def Minor fixes 2019-02-20 10:30:51 -07:00
David Ungar
8e7ff01caa WIP 2019-02-19 15:09:46 -07:00
David Ungar
d776cf5996 Some reordering 2019-02-19 15:03:42 -07:00
David Ungar
edaec2aea5 Move searchPlacesToSearch into PlacesToSearch 2019-02-19 11:24:51 -07:00
David Ungar
ef9f99e37c Rename ExpUnqalifiedLookup to UnqualifiedLookup, UnqualifiedLookup to LegacyUnqualifiedLookup 2019-02-19 10:55:44 -07:00
David Ungar
65f8f73992 Todo editing 2019-02-19 10:22:11 -07:00
David Ungar
0aee0dba4b 1st cut finish redo, unfmt 2019-02-18 15:30:18 -07:00
David Ungar
272df9f3b7 Minor return cleanup. 2019-02-17 23:23:27 -07:00
David Ungar
b52b85b884 Factor isCascadingUse resolution. 2019-02-17 23:07:01 -07:00
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