Commit Graph

24822 Commits

Author SHA1 Message Date
Doug Gregor
cc11fc6838 [Type checker] Introduce a request for computing the type of a pattern.
Compute the "raw" type of a pattern via a request, caching the result
of TypeChecker::typeCheckPattern(). Retain typeCheckPattern() as the
general entrypoint for performing this computation so that other code
doesn't need to change yet.
2020-01-03 16:14:48 -08:00
Doug Gregor
033f9c7927 [Type checker] Introduce "contextual patterns".
Contextual pattern describes a particular pattern with enough
contextual information to determine its type. Use this to simplify
TypeChecker::typeCheckPattern()'s interface in a manner that will
admit request'ification.
2020-01-03 15:41:21 -08:00
Robert Widmann
96b3b9f0f4 [NFC] Hide SourceFile::Decls
In preparation for installing some stable paths infrastructure here,
hide access to the array of top-level decls.
2020-01-03 14:14:00 -08:00
swift_jenkins
f27c28c85c Merge remote-tracking branch 'origin/master' into master-next 2020-01-03 12:59:03 -08:00
Slava Pestov
3997aa5754 SIL: Remove SILBuilder::tryCreateUncheckedRefCast() 2020-01-03 15:37:19 -05:00
Michael Gottesman
990af4bdd3 [sil] Change TermInst::getSuccessorBlockArguments() to yield SILArguments instead of SILPhiArgument since I am going to be adding SwitchEnumResult (which the API can vend as well). 2020-01-03 11:12:48 -08:00
swift_jenkins
dd0a12e971 Merge remote-tracking branch 'origin/master' into master-next 2020-01-03 08:59:01 -08:00
Holly Borla
475b5591ed Merge pull request #28979 from hborla/ambiguous-call-diagnostics
[ConstraintSystem] Start to allow diagnosing ambiguity with fixes for solution sets with more than one fix.
2020-01-03 08:49:30 -08:00
swift_jenkins
59776a04db Merge remote-tracking branch 'origin/master' into master-next 2020-01-03 08:19:08 -08:00
Michael Gottesman
1bebee1442 Merge pull request #28981 from gottesmm/pr-546e21d45833bff168ae44067649e52912207d47
[sil] Now that we aren't using mark-uninitialized-fixup anywhere, remove it.
2020-01-03 08:13:13 -08:00
Holly Borla
9e73bb3176 [ConstraintSystem] Start to allow diagnosing ambiguity with fixes
for solution sets with more than one fix.
2020-01-02 23:48:16 -08:00
swift_jenkins
cd9d23d5c4 Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 17:19:15 -08:00
Doug Gregor
79776436d8 Merge pull request #28984 from DougGregor/de-de-virtualize-for-each
[Type checker] Stop devirtualizing the reference to IteratorProtocol.next()
2020-01-02 17:08:59 -08:00
kelvin13
ed2552a694 fix merge conflict and update caseless stdlib enums to use synthesized Comparable 2020-01-02 18:40:50 -06:00
swift_jenkins
18970c39a4 Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 16:19:19 -08:00
Rintaro Ishizaki
5e35adc6e3 Merge pull request #28951 from kitaisreal/separated-do-while-blocks-diagnostic-correction
[Parse]: Separate do and while blocks diagnostics
2020-01-02 16:14:38 -08:00
swift_jenkins
add386ded3 Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 15:59:15 -08:00
Doug Gregor
716c72cadb Merge pull request #28380 from DougGregor/for-each-in-constraint-solver
[Type checker] Fold more for-each type checking into the constraint solver
2020-01-02 15:43:46 -08:00
Doug Gregor
97b5a0d5fb [Type checker] Stop devirtualizing the reference to IteratorProtocol.next().
Rather than having the type checker look for the specific witness to
next() when type checking the for-each loop, which had the effect of
devirtualizing next() even when it shouldn't be, leave the formation
of the next() reference to SILGen. There, form it as a witness
reference, so that the SIL optimizer can choose whether to
devirtualization (or not).
2020-01-02 14:39:00 -08:00
Doug Gregor
f22a7e2880 [AST] Drop makeIterator reference from ForEachStmt.
Rather than having the type checker form the ConcreteDeclRef for
makeIterator, have SILGen do it, because it's fairly trivial.
Eliminates some redundant state from the AST.
2020-01-02 13:29:13 -08:00
Michael Gottesman
5b557afbbe [sil] Now that we aren't using mark-uninitialized-fixup anywhere, remove it. 2020-01-02 12:10:36 -08:00
Doug Gregor
bbcaf8c669 [Type checker] Introduce value witness constraints.
Introduce a new kind of constraint, the "value witness" constraint,
which captures a reference to a witness for a specific protocol
conformance. It otherwise acts like a more restricted form of a "value
member" constraint, where the specific member is known (as a
ValueDecl*) in advance.

The constraint is effectively dependent on the protocol
conformance itself; if that conformance fails, mark the type variables
in the resolved member type as "holes", so that the conformance
failure does not cascade.

Note that the resolved overload for this constraint always refers to
the requirement, rather than the witness, so we will end up recording
witness-method references in the AST rather than concrete references,
and leave it up to the optimizers to perform devirtualization. This is
demonstrated by the SIL changes needed in tests, and is part of the
wider resilience issue with conformances described by
rdar://problem/22708391.
2020-01-02 12:06:23 -08:00
swift_jenkins
96f5d97cf8 Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 11:39:05 -08:00
Saleem Abdulrasool
ed920fe094 Merge pull request #28953 from compnerd/imvu
SIL: explicitly instantiate the `Operand` move ctor
2020-01-02 11:24:58 -08:00
swift_jenkins
81c0ed297a Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 10:19:08 -08:00
Saleem Abdulrasool
88dbd7a175 Merge pull request #28967 from compnerd/editor
build: improve libedit handling for builds
2020-01-02 10:16:50 -08:00
Saleem Abdulrasool
bf37455312 Merge pull request #28954 from compnerd/brace-yourself
SIL: use `std::array` for `SILSuccessor` array
2020-01-02 10:08:25 -08:00
Saleem Abdulrasool
f2a2a8218b Merge pull request #28943 from compnerd/lexicography
GSB: inline some trivial methods
2020-01-02 10:07:58 -08:00
Saleem Abdulrasool
87341e3296 Merge pull request #28939 from compnerd/shadow-walker
disambiguate some type shadowing (NFCI)
2020-01-02 10:06:09 -08:00
Saleem Abdulrasool
21ae72928e Merge pull request #28936 from compnerd/party-like-its-2017
remove VS2015 workaround (NFC)
2020-01-02 10:05:23 -08:00
Robert Widmann
19cc6ff844 Merge pull request #28922 from CodaFi/neo-compl-cache
[NFC] One-Shot Name Lookup + Lazily-Complete Base Name Cache
2020-01-02 13:04:17 -05:00
Doug Gregor
c5a655e35b [Type checker] Fold more for-each type checking into the constraint solver.
The type checking of the for-each loop is split between the constraint
solver (which does most of the work) and the statement checker (which
updates the for-each loop AST). Move more of the work into the constraint
solver proper, so that the AST updates can happen in one place, making use
of the solution produced by the solver. This allows a few things, some of
which are short-term gains and others that are more future-facing:

* `TypeChecker::convertToType` has been removed, because we can now either
use the more general `typeCheckExpression` entry point or perform the
appropriate operation within the constraint system.
* Solving the constraint system ensures that everything related to the
for-each loop full checks out
* Additional refactoring will make it easier for the for-each loop to be
checked as part of a larger constraint system, e.g., for processing entire
closures or function bodies (that’s the futurist bit).
2020-01-02 09:55:39 -08:00
swift_jenkins
79952615d1 Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 09:39:11 -08:00
Saleem Abdulrasool
075a93a475 SIL: add an explicit move assignment operation instantiation 2020-01-01 13:16:45 -08:00
Saleem Abdulrasool
86ca0a1747 SIL: explicitly instantiate the Operand move ctor
GCC 7 does not like the missing move constructor and does not implicitly
synthesize one.  Explicitly indicate that this should be synthesized.
2020-01-01 13:15:55 -08:00
Saleem Abdulrasool
1b850a2afd build: improve libedit handling for builds
Use the FindLibEdit.cmake module from LLDB to properly control where
the libedit libraries are searched for and linked from as well as where
the headers come from. This uses the standard mechanisms which allows
users to control where libedit is pulled from (which is important for
cross-compilation).

This second version is more aggressive about pruning the libedit
handling.  The Ubuntu 14.04 version of libedit does not have
`histedit.h`, and the intent is to rely on that to determine if we have
unicode support or not.
2019-12-29 16:32:49 -08:00
Michael Gottesman
321185e82f [sil] Rename TermInst::{getSuccessorBlockArguments,getSuccessorBlockArgumentLists}()
This method returns argument lists, not arguments! We should add in the future
an additional API that returns a flap mapped range over all such argument lists
to cleanup some of this code. But at least now the name is more accurate.
2019-12-28 15:33:30 -08:00
Saleem Abdulrasool
2b17d366b4 SIL: use std::array for SILSuccessor array
The `SILSuccessor` type does not permit copy or move initialization.
Direct initialization is required, however, GCC7 seems unable to cope
with the direct initialization of the array of non-copyable UDTs.  Use a
`std::array` which can be direct-initialized.  This enables building
with GCC7.
2019-12-27 10:24:08 -08:00
Saleem Abdulrasool
e133b20718 GSB: inline some trivial methods
This inlines the comparators since GCC 7 objects to the definition
(which is probably due to scoping).  However, these methods are
templates, which must be visible to the consumers, and should therefore
be in the header.  Given the size, it seems reasonable to just inline
them.
2019-12-26 19:46:53 -08:00
Kita, Maksim
f40a67d9f8 SR-11148: Separate do and while blocks generate error from legacy diagnostic 2019-12-26 22:57:30 +03:00
Saleem Abdulrasool
7d8aac60ca disambiguate some type shadowing (NFCI)
Adjust the type shadowing identified by GCC 7.  The declaration shadows
a type which changes the meaning of the identifier subsequently.
2019-12-23 15:34:55 -08:00
Saleem Abdulrasool
01d5652999 remove VS2015 workaround (NFC)
VS2015 had an issue with the deletion of an operator.  Since VS2017 is
the minimum version that LLVM uses, we can assume that VS2017+ is in use
(_MSC_VER >= 1910).  Clean up the now defunct workaround.
2019-12-23 11:55:10 -08:00
Kita, Maksim
646e9ac77f SR-11889: Fixed code review issues 2019-12-22 14:42:47 +03:00
swift_jenkins
c341a65002 Merge remote-tracking branch 'origin/master' into master-next 2019-12-21 13:39:03 -08:00
Slava Pestov
746b58e8e1 Merge pull request #28917 from atrick/fix-escape
Fix a crash in StackPromotion; case not handled in EscapeAnalysis.
2019-12-21 16:35:09 -05:00
Andrew Trick
786c29a139 Fix a crash in StackPromotion; case not handled in EscapeAnalysis.
StackPromotion queries EscapeAnalysis. The escape information for the
result of an array semantic was missing because it was an ill-formed
call. This fix introduces a new check to determine whether a call is
well formed so it can be handled consistently everywhere.

Fixes <rdar://problem/58113508>
Interpreter/SDK/objc_fast_enumeration.swift failed on
iphonesimulator-i386

The bug was introduced here:
commit 8b926af49a
Author: Andrew Trick <atrick@apple.com>
Date:   Mon Dec 16 16:04:09 2019 -0800

    EscapeAnalysis: Add PointerKind and interior/reference flags

The bug can occur when a semantic "array.ininitialized"
call (Array.adoptStorage) at the SIL level has direct "release_value"
instructions that don't use the tuple_extract values corresponding to
the call's returned value. This is part of the tragedy of not
supporting multiple call results. When users of the call's result can
use either the entire tuple (which is a meaningless value), or the
individual tuple extracts, then there's no way to handle calls
uniformly.

The change that broke this was to remove the special handling of
TupleExtract instructions. That special handling was identical to the
way that any normal pointer projection is handled. So, as a
simplification, the new code just expects that case to be handled
naturally as a pointer projection. This case was already guarded by a
check to determine whether the TupleExtract was actually the result of
an array.uninitialized call, in which case the normal handling does
not apply. However, because of the weirdness mentioned above, the
handling of "array.ininitialized" may silently bail out. When that
happens, the TupleExtract gets neither the special handling, nor the
normal handling.

Note that the old special handling of TupleExtract was bizarre and
relied on corresponding weirdness in the code that handles
"array.uninitialized". The new code simply creates a separate graph
node for each result of the call, and creates the edges that exactly
correspond to load and stores on those results. So, rather than
reinstating the previous code, which I can't quite reason about, this
fix creates a single check to determine whether a TupleExtract is
treated as an "array.uninitialized" result or not, and use that check
in both places.
2019-12-21 01:11:55 -08:00
Robert Widmann
47a2bf3fdc [NFC] One-Shot Name Lookup
Simplify lookupDirect to attempt one-shot name lookup based on some ideas Slava had.  This means we'll try to perform a cache fill up front, then access the table rather than assuming the table is always (relatively) up to date and filling when we miss the first cache access.

This avoids a walk over the deserialized members of an extension that fails named lazy member loading.  Instead, we eagerly page the members of the extension into the table and remove it from consideration for lazy member loading entirely.

In the future, we can convince the Clang Importer to avoid falling off the lazy member loading happy path.
2019-12-20 17:30:33 -08:00
swift_jenkins
51b1e043db Merge remote-tracking branch 'origin/master' into master-next 2019-12-20 11:39:15 -08:00
Rintaro Ishizaki
ab0475178a [CodeCompletion] Eliminate CodeCompletionCallbacks::completeExpr()
Well, this does nothing. It just set the parser position twice and calls
the consumer's 'handleResults()' without any reason.
It seems it was intended to be a "fallback" completion, but it was never
implemented properly. So just remove it for now.

rdar://problem/58102910
2019-12-20 09:39:02 -08:00
Ravi Kandhadai
ef254c0e9c [Constant Evaluator] Add support for evaluating checked_cast_br
instruction and store_borrow.
2019-12-20 09:29:20 -08:00