Commit Graph

28 Commits

Author SHA1 Message Date
Erik Eckstein
7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00
Erik Eckstein
09b26e897d SILParser: don't accept instructions after "unreachable"
All instructions after an "unreachable" were not added to the function anyway and were leaking.
2020-09-11 11:09:29 +02:00
John McCall
ceff414820 Distinguish invocation and pattern substitutions on SILFunctionType.
In order to allow this, I've had to rework the syntax of substituted function types; what was previously spelled `<T> in () -> T for <X>` is now spelled `@substituted <T> () -> T for <X>`.  I think this is a nice improvement for readability, but it did require me to churn a lot of test cases.

Distinguishing the substitutions has two chief advantages over the existing representation.  First, the semantics seem quite a bit clearer at use points; the `implicit` bit was very subtle and not always obvious how to use.  More importantly, it allows the expression of generic function types that must satisfy a particular generic abstraction pattern, which was otherwise impossible to express.

As an example of the latter, consider the following protocol conformance:

```
protocol P { func foo() }
struct A<T> : P { func foo() {} }
```

The lowered signature of `P.foo` is `<Self: P> (@in_guaranteed Self) -> ()`.  Without this change, the lowered signature of `A.foo`'s witness would be `<T> (@in_guaranteed A<T>) -> ()`, which does not preserve information about the conformance substitution in any useful way.  With this change, the lowered signature of this witness could be `<T> @substituted <Self: P> (@in_guaranteed Self) -> () for <A<T>>`, which nicely preserves the exact substitutions which relate the witness to the requirement.

When we adopt this, it will both obviate the need for the special witness-table conformance field in SILFunctionType and make it far simpler for the SILOptimizer to devirtualize witness methods.  This patch does not actually take that step, however; it merely makes it possible to do so.

As another piece of unfinished business, while `SILFunctionType::substGenericArgs()` conceptually ought to simply set the given substitutions as the invocation substitutions, that would disturb a number of places that expect that method to produce an unsubstituted type.  This patch only set invocation arguments when the generic type is a substituted type, which we currently never produce in type-lowering.

My plan is to start by producing substituted function types for accessors.  Accessors are an important case because the coroutine continuation function is essentially an implicit component of the function type which the current substitution rules simply erase the intended abstraction of.  They're also used in narrower ways that should exercise less of the optimizer.
2020-03-07 16:25:59 -05:00
Hamish Knight
312f7ddc50 Parse Swift decls in one shot
Instead of interleaving typechecking and parsing
for SIL files, first parse the file for Swift
decls by skipping over any intermixed SIL decls.
Then we can perform type checking, and finally SIL
parsing where we now skip over Swift decls.

This is an intermediate step to requestifying the
parsing of a source file for its Swift decls.
2020-02-04 13:04:50 -08:00
Michael Gottesman
40a09c9c21 Fixup tests for -assume-parsing-unqualified-ownership-sil => [ossa] transition. 2018-12-18 00:49:32 -08:00
Michael Gottesman
0af0d5fddc [ownership] Replace ValueOwnershipKind::Trivial with ValueOwnershipKind::Any.
In a previous commit, I banned in the verifier any SILValue from producing
ValueOwnershipKind::Any in preparation for this.

This change arises out of discussions in between John, Andy, and I around
ValueOwnershipKind::Trivial. The specific realization was that this ownership
kind was an unnecessary conflation of the a type system idea (triviality) with
an ownership idea (@any, an ownership kind that is compatible with any other
ownership kind at value merge points and can only create). This caused the
ownership model to have to contort to handle the non-payloaded or trivial cases
of non-trivial enums. This is unnecessary if we just eliminate the any case and
in the verifier separately verify that trivial => @any (notice that we do not
verify that @any => trivial).

NOTE: This is technically an NFC intended change since I am just replacing
Trivial with Any. That is why if you look at the tests you will see that I
actually did not need to update anything except removing some @trivial ownership
since @any ownership is represented without writing @any in the parsed sil.

rdar://46294760
2018-12-04 23:01:43 -08:00
Michael Gottesman
be568902f2 [ownership] Always print out ownership argument annotations whether or not -enable-sil-ownership is passed in.
This is how we originally controlled whether or not we printed out ownership
annotations when we printed SIL. Since then, I have changed (a few months ago I
believe) the ownership model eliminator to know how to eliminate these
annotations from the SIL itself. So this hack can be removed.

As an additional benefit, this will let me rename -enable-sil-ownership to
-enable-sil-ownership-verifier. This will I hope eliminate confusion around this
option in the short term while I am preparing to work on semantic sil again.

rdar://42509812
2018-07-24 13:18:37 -07:00
Dan Zheng
d4091441f3 [Parse] Minor fix for parsing SIL BuiltinInst. (#17072)
* [Parse] Minor fix for parsing SIL BuiltinInst.

The expected token in the diagnostic should be ")", not "(".

* [Parse] Add test for SIL BuiltinInst parse error.
2018-06-11 09:02:23 -07:00
John McCall
ab3f77baf2 Make SILInstruction no longer a subclass of ValueBase and
introduce a common superclass, SILNode.

This is in preparation for allowing instructions to have multiple
results.  It is also a somewhat more elegant representation for
instructions that have zero results.  Instructions that are known
to have exactly one result inherit from a class, SingleValueInstruction,
that subclasses both ValueBase and SILInstruction.  Some care must be
taken when working with SILNode pointers and testing for equality;
please see the comment on SILNode for more information.

A number of SIL passes needed to be updated in order to handle this
new distinction between SIL values and SIL instructions.

Note that the SIL parser is now stricter about not trying to assign
a result value from an instruction (like 'return' or 'strong_retain')
that does not produce any.
2017-09-25 02:06:26 -04:00
Chris Lattner
ada5487153 add fixit tests to random other tests.
Swift SVN r31006
2015-08-04 20:35:36 +00:00
Joe Groff
c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00
John McCall
dc5a03a7bc Add IRGen support for error results from functions.
As part of this, re-arrange the argument order so that
generic arguments come before the context, which comes
before the error result.  Be more consistent about always
adding a context parameter on thick functions, even
when it's unused.  Pull out the witness-method Self
argument so that it appears last after the error
argument.

Swift SVN r26667
2015-03-28 02:00:17 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Jordan Rose
0b2541b58f Rename the standard library to "Swift" (instead of "swift")
This is more in line with all other modules currently on our system.
If/when we get our final name for the language, we're at least now set
up to rename the library without /too/ much trouble. (This is mostly just
a lot of searching for "import swift", "swift.", "'swift'", and '"swift"'.
The compiler itself is pretty much just using STDLIB_NAME consistently now,
per r13758.)

<rdar://problem/15972383>

Swift SVN r14001
2014-02-17 19:30:47 +00:00
Joe Groff
1bcf0ce630 SIL: Fix up the parsing of generic apply insts.
Now that SILFunctionTypes are decontextualized, we have a prayer of parsing SIL that uses generic functions. Fix up the parsing code for ApplyInst and PartialApplyInst so that it consumes the closing '>' after a substitution list and properly computes the substituted function type before resolving the types of the instruction operands.

Swift SVN r13777
2014-02-11 04:52:25 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Chris Lattner
394ca8f944 implement basic support for parsing the new form of attribute, though this
is only used by the sil parser.  The old form is still parsed.


Swift SVN r8906
2013-10-04 04:02:09 +00:00
Anna Zaks
2c529eb21a [SILParser] Parse basic block arguments in branch instructions
Added types when printing these args in the SIL printer.

As a side effect, I've removed the assertions that check
that we have the correct number of arguments in the Branch instruction
creation routines. The reason is that we do not have a complete block when
parsing and creating the branch instruction and it is possible to add
arguments to a basic block after creation. The assertion will be checked
by the SIL verifier.

Swift SVN r6818
2013-08-01 21:32:05 +00:00
Anna Zaks
c12b826816 [SILParser] Run SILVerifier after parsing SIL.
Swift SVN r6817
2013-08-01 21:32:03 +00:00
Joe Groff
ba774364f1 SIL: Have SILModules track their SILStage.
Modules can be in either 'Raw' or 'Canonical' form, with different invariants on each. We don't actually distinguish those invariants yet, but this patch adds the field to SILModule and adds a "sil_stage" declaration to SIL printer/parser syntax.

Swift SVN r6793
2013-08-01 00:58:31 +00:00
Chris Lattner
b13c50157e implement proper name binding and resolution of global sil function names, including
diagnosing redefinitions, use of undefined values, handling forward references, etc.



Swift SVN r5908
2013-06-30 19:31:19 +00:00
Chris Lattner
5c661f3c38 push global reference parsing forward a bit, diagnosing a type error.
Swift SVN r5811
2013-06-26 05:33:49 +00:00
Chris Lattner
a5c7c65ee7 Move around the logic for handling autoimport of the swift standard
library.  We use the same (somewhat broken heuristics), they are
just implemented in another way.

The major functionality change is that previously, .sil files would
auto import "swift" if they started with a non-sil decl.  Now they
never do.



Swift SVN r5731
2013-06-20 23:39:27 +00:00
Chris Lattner
c801ea6de0 diagnose use of undefined values.
Swift SVN r5345
2013-05-25 22:19:26 +00:00
Chris Lattner
2e69c61f71 Implement more reasonable local value name lookup:
- Allow forward references.
  - Diagnose redefinitions.
  - Diagnose cases where the use/def of a value mismatch type.

While I'm at it, this fixes a bug where tuple parsing wasn't parsing
the separating commas.


Swift SVN r5343
2013-05-25 18:42:38 +00:00
Chris Lattner
44cdd1d59d parse and build tuple and return instructions. Add a terrible hack at
local name lookup.


Swift SVN r5334
2013-05-25 16:12:42 +00:00
Chris Lattner
ce314e59c1 - introduce a form of Parser::parseIdentifier that captures a token location,
requiring us to make the variadic templates a bit more specific.

- Make SIL parser tests use updated syntax (still not parsed).


Swift SVN r5312
2013-05-24 23:59:21 +00:00
Chris Lattner
39d0d13dbb Diagnose SIL BB redefinition errors, add a testcase to check error conditions.
Swift SVN r5278
2013-05-22 23:03:31 +00:00