Commit Graph

640 Commits

Author SHA1 Message Date
Slava Pestov
6702d38d87 Sema: Remove most calls to Decl::setValidationToChecked() 2019-10-03 17:11:45 -04:00
Mishal Shah
2f86d67500 Merge pull request #27396 from shahmishal/master-rebranch
Update master to support apple/stable/20190619 branch for LLVM projects
2019-10-01 10:50:49 -07:00
swift-ci
5e50242b5e Merge remote-tracking branch 'origin/master' into master-next 2019-09-30 16:09:53 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
Harlan Haskins
d4247942c4 Merge remote-tracking branch 'upstream/master' into master-next 2019-09-26 20:19:25 -07:00
Harlan Haskins
e349b7b123 Merge branch 'master' into master-rebranch 2019-09-26 20:16:05 -07:00
Jordan Rose
a6dd630ca3 Eliminate Builtin.UnknownObject as an AST type (#27378)
This removes it from the AST and largely replaces it with AnyObject
at the SIL and IRGen layers. Some notes:

- Reflection still uses the notion of "unknown object" to mean an
  object with unknown refcounting. There's no real reason to make
  this different from AnyObject (an existential containing a
  single object with unknown refcounting), but this way nothing
  changes for clients of Reflection, and it's consistent with how
  native objects are represented.

- The value witness table and reflection descriptor for AnyObject
  use the mangling "BO" instead of "yXl".

- The demangler and remangler continue to support "BO" because it's
  still in use as a type encoding, even if it's not an AST-level
  Type anymore.

- Type-based alias analysis for Builtin.UnknownObject was incorrect,
  so it's a good thing we weren't using it.

- Same with enum layout. (This one assumed UnknownObject never
  referred to an Objective-C tagged pointer. That certainly wasn't how
  we were using it!)
2019-09-26 17:48:04 -07:00
Alex Langford
8e1862774b Adjust for svn rL372380
This added two new values to llvm::ITTDescriptor. These are not yet supported in
swift so we return an empty type, just like the other intrinsics.
2019-09-23 13:44:23 -07:00
swift-ci
5343bef360 Merge remote-tracking branch 'origin/master' into master-next 2019-09-21 02:29:31 -07:00
swift-ci
78ff7eae0f Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-21 02:23:44 -07:00
Michael Gottesman
e90a68fa17 [polymorphic-builtins] Teach dataflow diagnostics how to emit an error if it sees an unspecialized polymorphic builtin.
This will ensure that if an expert user is using this feature and makes a
mistake as a result of tweaking their code, they get an error. This will ensure
they do not ship and look into why this is happening.

This is not intended to be used by anyone except for expert stdlib users.
2019-09-20 17:25:56 -07:00
swift-ci
1155f033a4 Merge remote-tracking branch 'origin/master' into master-next 2019-09-19 13:29:07 -07:00
swift-ci
f0d946690f Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-19 13:23:38 -07:00
Michael Gottesman
20c5dff4b5 [builtin] Implement polymorphic builtins for all BUILTIN_BINARY_OPERATIONs.
TLDR: This patch introduces a new kind of builtin, "a polymorphic builtin". One
calls it like any other builtin, e.x.:

```
Builtin.generic_add(x, y)
```

but it has a contract: it must be specialized to a concrete builtin by the time
we hit Lowered SIL. In this commit, I add support for the following generic
operations:

Type           | Op
------------------------
FloatOrVector  |FAdd
FloatOrVector  |FDiv
FloatOrVector  |FMul
FloatOrVector  |FRem
FloatOrVector  |FSub
IntegerOrVector|AShr
IntegerOrVector|Add
IntegerOrVector|And
IntegerOrVector|ExactSDiv
IntegerOrVector|ExactUDiv
IntegerOrVector|LShr
IntegerOrVector|Mul
IntegerOrVector|Or
IntegerOrVector|SDiv
IntegerOrVector|SRem
IntegerOrVector|Shl
IntegerOrVector|Sub
IntegerOrVector|UDiv
IntegerOrVector|Xor
Integer        |URem

NOTE: I only implemented support for the builtins in SIL and in SILGen. I am
going to implement the optimizer parts of this in a separate series of commits.

DISCUSSION
----------

Today there are polymorphic like instructions in LLVM-IR. Yet, at the
swift and SIL level we represent these operations instead as Builtins whose
names are resolved by splatting the builtin into the name. For example, adding
two things in LLVM:

```
  %2 = add i64 %0, %1
  %2 = add <2 x i64> %0, %1
  %2 = add <4 x i64> %0, %1
  %2 = add <8 x i64> %0, %1
```

Each of the add operations are done by the same polymorphic instruction. In
constrast, we splat out these Builtins in swift today, i.e.:

```
let x, y: Builtin.Int32
Builtin.add_Int32(x, y)
let x, y: Builtin.Vec4xInt32
Builtin.add_Vec4xInt32(x, y)
...
```

In SIL, we translate these verbatim and then IRGen just lowers them to the
appropriate polymorphic instruction. Beyond being verbose, these prevent these
Builtins (which need static types) from being used in polymorphic contexts where
we can guarantee that eventually a static type will be provided.

In contrast, the polymorphic builtins introduced in this commit can be passed
any type, with the proviso that the expert user using this feature can guarantee
that before we reach Lowered SIL, the generic_add has been eliminated. This is
enforced by IRGen asserting if passed such a builtin and by the SILVerifier
checking that the underlying builtin is never called once the module is in
Lowered SIL.

In forthcoming commits, I am going to add two optimizations that give the stdlib
tool writer the tools needed to use this builtin:

1. I am going to add an optimization to constant propagation that changes a
"generic_*" op to the type of its argument if the argument is a type that is
valid for the builtin (i.e. integer or vector).

2. I am going to teach the SILCloner how to specialize these as it inlines. This
ensures that when we transparent inline, we specialize the builtin automatically
and can then form SSA at -Onone using predictable memory access operations.

The main implication around these polymorphic builtins are that if an author is
not able to specialize the builtin, they need to ensure that after constant
propagation, the generic builtin has been DCEed. The general rules are that the
-Onone optimizer will constant fold branches with constant integer operands. So
if one can use a bool of some sort to trigger the operation, one can be
guaranteed that the code will not codegen. I am considering putting in some sort
of diagnostic to ensure that the stdlib writer has a good experience (e.x. get
an error instead of crashing the compiler).
2019-09-19 11:42:10 -07:00
swift-ci
5d7bd0a29b Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-18 10:24:59 -07:00
swift-ci
a453eda2dc Merge remote-tracking branch 'origin/master' into master-next 2019-09-18 10:09:53 -07:00
Jordan Rose
f73c4c43c4 Merge pull request #27225 from jrose-apple/absolute-unit
[AST] Split FileUnit and SourceFile out of Module.h
2019-09-18 10:04:40 -07:00
swift-ci
1fdda8eaa8 Merge remote-tracking branch 'origin/master' into master-next 2019-09-17 19:09:48 -07:00
swift-ci
1fe9aa60dd Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-17 19:03:56 -07:00
Jordan Rose
853caa66d4 [AST] Split FileUnit and its subclasses out of Module.h
Most of AST, Parse, and Sema deal with FileUnits regularly, but SIL
and IRGen certainly don't. Split FileUnit out into its own header to
cut down on recompilation times when something changes.

No functionality change.
2019-09-17 17:54:41 -07:00
Ravi Kandhadai
b59cc7ad6a [Constant Evaluator] Add support to the constant evaluator for:
1. builtin "int_expect", which makes the evaluator work on more
integer operations such as left/right shift (with traps) and
integer conversions.

2. builtin "_assertConfiguration", which enables the evaluator
to work with debug stdlib.

3. builtin "ptrtoint", which enables the evaluator to track
StaticString

4. _assertionFailure API, which enables the evaluator to report
stdlib assertion failures encountered during constant evaluation.

Also, enable attaching auxiliary data with the enum "UnknownReason"
and use it to improve diagnostics for UnknownSymbolicValues,
which represent failures during constant evaluation.
2019-09-16 15:12:22 -07:00
Mike Ash
f5e7ab866c Merge branch 'master' into master-next 2019-09-09 12:11:25 -04:00
swift-ci
5b3fdba240 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-06 17:23:34 -07:00
Slava Pestov
f292c1b240 AST: Remove GenericContext::setGenericEnvironment()
This was a transitional step before converting all callers to
store a generic signature instead of an environment.
2019-09-06 17:16:04 -04:00
Slava Pestov
1e94466bcc AST: Replace GenericSignature::createGenericEnvironment() with getGenericEnvironment()
This memoizes the result, which is fine for all callers; the only
exception is open existential types where each new open existential
now explicitly gets a unique generic environment, allocated by
calling GenericEnvironment::getIncomplete().
2019-09-06 17:16:03 -04:00
swift-ci
333320679f Merge remote-tracking branch 'origin/master' into master-next 2019-08-28 19:30:21 -07:00
swift-ci
4e9cf240bd Merge remote-tracking branch 'origin/master' into master-rebranch 2019-08-28 19:24:21 -07:00
Nikolai Vazquez
ba0612f2e9 Add Builtin.isConcrete<T>(T.Type) -> Int1
Returns `true` if `T.Type` is known to refer to a concrete type. The
implementation allows for the optimizer to specialize this at -O and
eliminate conditional code.

Includes `Swift._isConcrete<T>(T.Type) -> Bool` wrapper function.
2019-08-27 16:51:09 -07:00
Davide Italiano
bf2b57bef0 [AST] Catch up with the newly introduced builtin.
Unbreaks master-next.
2019-08-27 15:51:30 -07:00
Arnold Schwaighofer
20efacf2d6 Merge remote-tracking branch 'upstream/master' into master-next 2019-08-26 13:30:41 -07:00
swift-ci
abb9f9b8ab Merge remote-tracking branch 'origin/master' into master-rebranch 2019-08-26 11:05:16 -07:00
Doug Gregor
0f80384942 [AST] Switch builtin creation over to the abstract generic signature request 2019-08-26 09:54:20 -07:00
Brent Royal-Gordon
fb20b503ba Merge branch 'master' into master-rebranch
# Conflicts:
#	lib/ClangImporter/ClangImporter.cpp
#	test/IRGen/builtins.swift
#	test/IRGen/enum.sil
#	tools/driver/autolink_extract_main.cpp
#	utils/build-presets.ini
2019-08-08 17:07:59 -07:00
swift-ci
390e58228d Merge remote-tracking branch 'origin/master' into master-next 2019-07-22 20:30:09 -07:00
Slava Pestov
a532a325e1 AST: Move a few methods from VarDecl down to ParamDecl 2019-07-22 20:19:09 -04:00
Joe Groff
d38a72c4ad Merge branch 'master' into master-next 2019-07-18 13:14:39 -07:00
eeckstein
63a1a42643 Merge pull request #26185 from eeckstein/old-condfail
Support the old single-parameter Builtin.condfail
2019-07-18 13:38:47 +02:00
Michael Gottesman
eb9b24104e Merge pull request #26158 from gottesmm/pr-ed0fb2c51d1ce701156c957f511f6ee3b57f1e7a
[ast] Refactor Builtin printing logic from ASTPrinter -> BuiltinInst.
2019-07-17 11:24:56 -07:00
Erik Eckstein
340b0ed001 Support the old single-parameter Builtin.condfail
We have to be source compatible to be able to parse old swiftinterface files where the old Builtin.condfail is used in inlineable functions.

rdar://problem/53176692
2019-07-17 17:41:59 +02:00
Erik Eckstein
117b1dafe6 Rename the two-parameter Builtin.condfail(c, message) to Builtin.condfail_message(c, message)
This is necessary to also support the old single paramter Builtin.condfail(c)
2019-07-17 17:41:59 +02:00
Michael Gottesman
f952ff0ee4 [ast] Move printing code from ASTPrinter onto a helper on BuiltinType and have ASTPrinter call that instead. 2019-07-16 23:26:01 -07:00
Erik Eckstein
b40ce6b34f SIL: add a failure message operand to Builtin.condfail
The SIL generation for this builtin also changes: instead of generating the cond_fail instructions upfront, let the optimizer generate it, if the operand is a static string literal.
In worst case, if the second operand is not a static string literal, the Builtin.condfail is lowered at the end of the optimization pipeline with a default message: "unknown program error".
2019-07-16 14:44:09 +02:00
Brent Royal-Gordon
d5a2912a26 Revert "Better runtime failure messages (not yet enabled by default)" 2019-07-15 13:42:40 -07:00
Erik Eckstein
3fd7eea96c SIL: add a failure message operand to Builtin.condfail
The SIL generation for this builtin also changes: instead of generating the cond_fail instructions upfront, let the optimizer generate it, if the operand is a static string literal.
In worst case, if the second operand is not a static string literal, the Builtin.condfail is lowered at the end of the optimization pipeline with a default message: "unknown program error".
2019-07-12 14:03:13 +02:00
swift-ci
f1cdb876a4 Merge remote-tracking branch 'origin/master' into master-next 2019-07-03 19:49:53 -07:00
Ravi Kandhadai
5430aa0b17 [Builtin][SILGen][IRGen] Create a new builtin "globalStringTablePointer":
String -> Builtin.RawPointer that given a string constructed from a
literal, returns the address of the string literal in the global string
table of the compiled binary as a pointer.
2019-07-03 16:47:34 -07:00
Saleem Abdulrasool
649db5c6f7 AST: adjust for SVN r363240
A new Intrinsic Info Table type `VecElementArgument` has been introduced
upstream.  Account for it in the covered switch.
2019-06-13 08:46:14 -07:00
Argyrios Kyrtzidis
04992a58d1 [CMake] Provide a way to build the minimum things necessary for the syntax parser library
These changes allow to optionally perform a very fast build that is targeted to only produce the syntax parser library.
Part of addressing rdar://48153331
2019-02-23 11:31:31 -08:00
John McCall
b1be41a1d2 Implement some more LLVM intrinsic type-decoding rules. 2019-02-08 14:22:57 -08:00
Pavel Yaskevich
64fa0ee729 [TypeChecker] Add Builtin operation to trigger/test fallback diagnostic 2019-01-07 10:42:00 -08:00