Commit Graph
25 Commits
Author SHA1 Message Date
Richard Smith 7fe06a5d2f Unify handling of calls to functions and to methods. (#2620)
This fixes some bugs in each, where the fixes had only been made on one
side of the switch or the other. Also don't forget to instantiate
deduced generic arguments in a call when we read them out of the AST.
2023-02-22 13:51:25 -08:00
Richard Smith 4daaa4866f Rename Type -> type, per #2360. (#2507)
Also make minor updates to the skeletal design in
docs/design/name_lookup.md following #2113, as there are no longer any prelude names that are made available to unqualified name lookup by default.

Add `type` to the keyword list in
docs/design/lexical_conventions/words.md, following #2360.
2023-01-04 14:22:30 -08:00
josh11b 9c8fd6864e Implement rename me -> self (#2444)
Implements change proposed in #1382

Replaces #1624
2022-12-06 20:17:00 -08:00
Richard Smith 0219218b01 Make type contexts expect a value of type Type. (#2357)
In particular, this means that a type can implement `ImplicitAs(Type)` and have values of that type behave like types.

This implies that `()` and `{}` are no longer types. They are now values whose type is the result of converting `()` or `{}` to type `Type`, as has been discussed recently and seems to be the supported direction. This fixes various cases where these types were previously mishandled.
2022-10-28 08:20:49 -07:00
Jon Ross-Perkins eac7c2bda4 Automate the addition of RUN and simplify RUN lines (#2292)
This was an offshoot of the discussion about how much boilerplate we could remove. lit requires RUN lines be there, everything else is optional.
2022-10-17 13:52:37 -07:00
Jon Ross-Perkins e111418b32 Merge and label stdout/stderr for FileCheck (#2283)
Adds a simple script to merge stdout/stderr and put on labels. This is hidden to the RUN line using lit.cfg.py.

This is my solution to addressing how errors printed by the toolchain break sorting of stdout output; just put stdout first. We could also have toggles for interleaving output or such, which might help test whether we do it properly.

This also moves some previous-distributed replacement logic into lit_autoupdate_base.py: I think having that adjacent to lit.cfg.py is probably the better choice, and it reduces duplication in toolchain scripts. It happens here because I need to change the resulting commands to include the merge.
2022-10-13 14:46:30 -07:00
Richard Smith b1c50bd6a7 Revert "Fix: Issue #1394 (#2266)" (#2285)
This change left a test broken and removed a fair amount of test coverage for unrelated features, and after further discussion it's not clear that this is the direction we want to go in.

This reverts commit 6cf2272bbe.
2022-10-13 12:15:56 -07:00
6cf2272bbe Fix: Issue #1394 (#2266)
* start correct

* Fix #1394

* remove llvm::outs()

* Fix #1394

* ---

* fix issue-1394

* fix issue-1394

* Update explorer/interpreter/interpreter.cpp

Co-authored-by: Geoff Romer <gromer@google.com>

* fix issue-1394

* remove and rename test files

* add changes from j.m

Co-authored-by: m new <michael.burzan@outlook.de>
Co-authored-by: Geoff Romer <gromer@google.com>
2022-10-13 19:44:53 +02:00
Richard Smith 9f534ae004 Implement support for rewrite constraints (#2276)
Implements basic support for rewrite constraints as proposed in #2173.

Support for associated constants and complex constraints in general is also made more robust: argument deduction now properly computes and substitutes witnesses, and interface declarations track a more correct description of the constraint that they introduce than the one we previously built.
2022-10-12 12:55:55 -07:00
Richard Smith 9feff92f22 Track witnesses wherever possible (#2263)
Change explorer's handling of witnesses to track them wherever possible. Associated constant support needs witnesses to be available much more pervasively.

The main changes here are:

-   `Substitute` now takes a set of bindings covering both `Value`s for `GenericBinding`s and `Witness`es for `ImplBinding`s, and substitutes both.
-   Witnesses are now tracked within `ConstraintType`s. The `.Self` type has an `ImplBinding` that self-references from parts of the constraint to other parts of the constraint can use to access the witness for the constraint.
-   The constraint type for an `impl` and for a `GenericBinding` are now stored in pre-substituted form, with references to the actual constrained type rather than symbolic references to `.Self`. This results in minor changes in diagnostic text.

Argument deduction still performs substitutions without remapping witnesses.
2022-10-11 15:20:23 -07:00
Jon Ross-Perkins b9d3d9a3df Unify lit.cfg.py approach (#2249)
On #2224 @zygoloid pointed out we needed --implicit-check-not to ensure we were correctly matching output. This is the standard way we're writing explorer tests, so I was looking at unifying our lit approaches.

This is one take on it, making more use of substitutions to bring various testing into alignment, as well as symlinks to avoid config skew (maybe I'll eventually figure out a better solution than symlinks).

Makes a couple small fixes in explorer to remove end-of-line whitespace on output.
2022-10-06 12:25:23 -07:00
Richard Smith 8f0f69b65f Remove RuntimeError / CompilationError. (#2258)
Instead, work out the prefix for an error based on whether it was produced during parsing, semantic analysis, or when running the program.
2022-10-04 15:39:04 -07:00
2c921efe36 Fix for: missing check that deduced argument converts to type of parameter #1300 (#1918)
Fix #1300

Co-authored-by: m new <michael.burzan@outlook.de>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2022-08-09 14:47:52 -07:00
Richard Smith e26bc32343 Change remaining uses of Bool to bool, following #750. (#1901)
The most significant change here is that explorer now uses the chosen spelling
rather than the old `Bool` spelling. Also update a few documentation examples
and some skeletal design docs to use the chosen spelling.
2022-08-03 17:55:34 -07:00
Richard Smith f3127d2e83 Fix test failure due to racing commits. (#1802) 2022-07-28 09:25:14 -07:00
Richard Smith 15ec5113aa Add extensibility support for arithmetic operators. (#1751)
Add new prelude interfaces `Negate`, `AddWith`, `SubWith`, and `MulWith`, and
use them to implement non-builtin arithmetic operations.
2022-07-27 15:09:27 -07:00
Richard Smith 7a67715ac5 Error: track message and prefix/location separately. (#1529)
This allows us to combine multiple Errors together without repeating the prefix
information. Also fixes several cases where two "COMPILATION ERROR" prefixes
would be prepended to the same message when errors with prefixes and locations
were produced by the lexer and parser.
2022-07-26 15:08:19 -07:00
Richard Smith 93e19649aa Support for as operator and user-defined As impls. (#1476) 2022-07-21 13:16:18 -07:00
Richard SmithandJon Ross-Perkins 663ed32b1b Initial support for associated constants (#1376)
Basic support for declaring, specifying the values of, and using associated constants.

This is incomplete in various ways. For example, when checking whether a type satisfies a constraint, there is no check that its associated constants match those in the constraint, and name lookup into a value whose type is an associated constant is not supported yet.

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
2022-07-14 18:18:27 -07:00
Jeremy G. Siek b759401328 Heap allocation basics (#1323)
* initial implementation of new and delete

* remove requirement for empty heap from trace.carbon

* more tests

* fixed substitution for generic function types
2022-06-11 18:47:07 -04:00
Richard Smith b74d3f80f1 Add a new kind of Witness value that carries an expression (#1324)
This renames `Witness` to `ImplWitness` and adds a new form, `SymbolicWitness`, that holds an expression by which a witness can be computed. A common base class `Witness` is provided.

We form the new kind of witness when evaluation of a witness expression fails because the witness is not in scope, as happens when evaluating a subexpression such as a type expression in isolation, and retry evaluation in the larger context when the interpreter performs type instantiation when running the code.

This allows us to properly handle compile-time evaluation of constructs involving witness table lookups when the witness can be statically determined. The intent is that we will eventually also form symbolic witness table references when impl selection finds a non-final witness, in order to support specialization.

Simplify `NominalClassValue`: it can now always store a witness map rather than either a witness map or a witness-or-witness-expression map.
2022-06-10 14:16:54 -07:00
pk19604014 f0a34e4bf7 Added TypeCheckTypeExp() and changed function type literal and similar type-checking logic to use the new function (#1256) 2022-05-23 16:26:35 -07:00
Richard SmithandJon Meow c29f56e667 Initial support for generic parameters that are introduced in a function parameter list (#1247)
In order for this to work, we need to always use the argument deduction code path for function calls, instead of only using it when there is a `[...]` list, which means that argument deduction now needs to support implicit conversion.

Co-authored-by: Jon Meow <jperkins@google.com>
2022-05-12 08:48:19 -07:00
Richard SmithandJon Meow e85f45de10 Move CHECK lines in tests next to the line that caused the output. (#1224)
Use FileCheck's `[[@LINE+n]]` mechanism to refer to the next line.

This is made awkward by a couple of things:

* We want to keep the `CHECK` lines in the original order.
* Errors are sometimes more than one line long.

The approach we use is to interleave the original lines and the check lines, putting each check line as early as possible subject to two rules:

1) Check lines never precede the 'AUTOUPDATE' line
2) Except when required by rule (1), a check line that refers to a source line by line number is never placed earlier than a source line that precedes that source line.

The actual `[[@LINE+n]]` annotations are created in a second pass after we've interleaved the lines so that we can work out the correct offsets.

Co-authored-by: Jon Meow <jperkins@google.com>
2022-05-03 15:48:56 -07:00
Jon Meow 309ec35f95 Rename executable_semantics to explorer (#1188)
Change generated with:

```
#!/usr/bin/bash -eux

# Helper script for renaming pending work.
# Run from the repo root.

# Rename executable_semantics in code.
sed -i 's/executable_semantics/explorer/g' \
  $(git grep -l 'executable_semantics' . | grep -v proposals)
sed -i 's/executable semantics/explorer/g' \
  $(git grep -l 'executable semantics' . | grep -v proposals)
sed -i 's/Executable semantics/Explorer/g' \
  $(git grep -l 'Executable semantics' . |  grep -v proposals)
sed -i 's/Executable Semantics/Explorer/g' \
  $(git grep -l 'Executable Semantics' . |  grep -v proposals)
sed -i 's/EXECUTABLE_SEMANTICS/EXPLORER/g' \
  $(git grep -l 'EXECUTABLE_SEMANTICS' . | grep -v proposals)
sed -i 's/ExecutableSemantics/Explorer/g' \
  $(git grep -l 'ExecutableSemantics' . | grep -v proposals)
sed -i 's/executable-semantics/explorer/g' \
  $(git grep -l 'executable-semantics' . | grep -v proposals)

# This is only needed for the initial move.
mv executable_semantics explorer
mv explorer/fuzzing/executable_semantics_fuzzer.cpp explorer/fuzzing/explorer_fuzzer.cpp
```

Verified with `bazel test ...`
2022-04-29 13:20:25 -07:00