Commit Graph

193248 Commits

Author SHA1 Message Date
bors[bot] eca2ac2c23
Merge #1453
1453: Add in -m32,-m64 configuration to make check-rust r=philberty a=philberty

This is to gate PR's which might break builds on 32bit systems.

Fixes #1439 #871


Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-08-10 11:06:18 +00:00
bors[bot] 7027e5c21a
Merge #1452
1452: transmute: Fix behavior by always performing the raw copy r=CohenArthur a=CohenArthur

This desugars calls to transmute the following way:

`transmute::<T1, T2>(value)`

->

`*((T2 *) &value)`

This always ends up being optimized into a simple copy for small types
and a memcpy for larger types.

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-08-10 10:35:07 +00:00
Arthur Cohen 71b5bc8705 transmute: Fix behavior by always performing the raw copy
This desugars calls to transmute the following way:

`transmute::<T1, T2>(value)`

->

`*((T2 *) &value)`

This always ends up being optimized into a simple copy for small types
and a memcpy for larger types.

Co-authored-by: philberty <philip.herron@embecosm.com>
2022-08-10 12:36:26 +02:00
bors[bot] 7c3766ccfc
Merge #1454
1454: intrinsics: Refactor compilation of intrinsics r=CohenArthur a=CohenArthur

This commit adds helpers around caching, compiling and using intrinsic
functions before extending them with instructions specific to the
intrinsic. We can refactor them further, but this is already a bit
easier to deal with when writing new intrinsics


Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-08-10 10:03:11 +00:00
Philip Herron 50bb06ce3b Seperate 64 and 32 bit testing combos into seperate jobs
Change the CI requirements to have seperate jobs for 64 and 32 bit testing.
It also runs both combinations on the gcc4.8 build job. Bors only requires
the normal build check 64bit job to pass to minimize impact.
2022-08-10 10:51:26 +01:00
Arthur Cohen fc8d5dfe93 intrinsics: Refactor compilation of intrinsics
This commit adds helpers around caching, compiling and using intrinsic
functions before extending them with instructions specific to the
intrinsic. We can refactor them further, but this is already a bit
easier to deal with when writing new intrinsics
2022-08-10 10:32:44 +02:00
bors[bot] 349b0f8ed4
Merge #1445
1445: compile: Move and rename `SimpleIntrinsics` -> BuiltinsContext r=CohenArthur a=CohenArthur

This will allow us to use the class for more than just math builtins


Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-08-10 06:29:06 +00:00
Arthur Cohen 45095d73f1 compile: Move and rename `SimpleIntrinsics` -> `BuiltinsContext`
This will allow us to use the class for more than just math builtins
2022-08-10 08:28:42 +02:00
Philip Herron 6496291f34 Enforce win64 abi test to always run on -m64 mode
Fixes #1439
2022-08-09 16:35:37 +01:00
Philip Herron fefd8633dc Remove 128bit code generation from test case
128 bit integer support is not always available for every GCC arch and we
will need to rely on runtime libraries for these operations in the future.

Addresses #1439
2022-08-09 16:18:33 +01:00
Philip Herron 4db24e3f2b Add in -m32,-m64 configuration to make check-rust
This is to gate PR's which might break builds on 32bit systems.

Addresses #1439
2022-08-09 15:33:31 +01:00
bors[bot] 5865fb27a7
Merge #1425 #1451
1425: Cleanup frontend entrypoint r=CohenArthur a=CohenArthur

This removes a lot of code that was simply ported from the Go frontend, and forbids the usage of multiple input files.

Addresses #1115

1451: Fix failiure to type inference on unit-structs r=philberty a=philberty

This patch set adds fixes to ensure we can type inference generic unit-structs.

Fixes #1447 

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-08-09 14:25:07 +00:00
bors[bot] 17b625cbd6
Merge #1444
1444: Handle `rustc_const_{un}stable` properly for intrinsics r=CohenArthur a=CohenArthur

Since extern functions cannot be marked as const (they take no
qualifiers) but some intrinsics are const, while still being `extern
"rust-intrinsic", we need to be able to handle the
`#[rustc_const_stable]` and `#[rustc_const_unstable]` attribute.

Technically, this simply indicates that a certain intrinsic is constant
and can be used in const contexts, such as `size_of` or `offset`.

We also need to mark all const intrinsics with `rustc_const_stable` in
the testsuite.

Closes #1440 

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-08-09 13:48:52 +00:00
Arthur Cohen 4ffd884a69 const-checker: Add `is_const_extern_fn` helper function
Co-authored-by: philberty <philip.herron@embecosm.com>
2022-08-09 09:37:41 +02:00
Philip Herron 92eef6c33d Fix type inference on unit-structs
When we initilize a structure that contains an identifier for the value
which resolves to a generic unit-struct. The unit struct has no fields
but it also contains a reference to a generic parameter which needs to be
infered this updates the code for identifiers to act like a
PathInExpression to infer the generic parameters when its unit struct only.

Fixes #1447
2022-08-08 17:24:48 +01:00
Philip Herron b9840366b6 Unify generic substitutions on unit-structs
When we have generic unit-structs there are no fields to unify the generic.
This adds a case to ensure we iterate and check these. We might end up
making it always do this for all structs always.

Addresses #1447
2022-08-08 17:23:27 +01:00
Philip Herron e0a14f4839 ADT's and tuples are valid to be unified with inference variables
There is some dulication here which will eventually go away with the
coercion site refactor which is still a WIP. Here we update the type rules
so that we allow ADT's and tuples to unify and thus fulfill the type
inference rules.

Addresses #1447
2022-08-08 17:08:01 +01:00
bors[bot] 8749b66879
Merge #1438
1438: Enhance #1426 "Invalid recursive :stmt expansion in fragment specifiers" test case r=philberty a=tschwinge

... that was recently added in #1429 commit 9fc6a27b5c "expand: correctly handles non-macro nodes ...".

  - Rename 'macro-issue1403.rs' -> 'macro-issue1426.rs'.
  - Get rid of '-w'; expect diagnostic instead.
  - Get rid of debugging options not relevant here.
  - Get rid of explicit '-O1'; make it a "torture" test case.
  - Replace always-matching 'scan-assembler "14"' ("14" appears in the crate name) with directed dump scanning.
      - ..., just not for '-O0', where such optimization is not done.


Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
2022-08-08 09:28:26 +00:00
Arthur Cohen 084f959076 attr: Handle `rustc_const_{un}stable` properly
Since extern functions cannot be marked as const (they take no
qualifiers) but some intrinsics are const, while still being `extern
"rust-intrinsic", we need to be able to handle the
`#[rustc_const_stable]` and `#[rustc_const_unstable]` attribute.

Technically, this simply indicates that a certain intrinsic is constant
and can be used in const contexts, such as `size_of` or `offset`.

We also need to mark all const intrinsics with `rustc_const_stable` in
the testsuite.
2022-08-08 09:07:54 +02:00
bors[bot] c8f65b3fc8
Merge #1442
1442: testsuite: test for diagnostics shown when a built-in macro does not exist r=CohenArthur a=liushuyu

- testsuite: test for diagnostics shown when a built-in macro does not exist

Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-08-08 05:47:41 +00:00
liushuyu ab9b1e4dea
testsuite: test for diagnostics shown ...
... when a built-in macro does not exist
2022-08-07 23:44:08 -06:00
Thomas Schwinge 23702abda4 Enhance #1426 "Invalid recursive :stmt expansion in fragment specifiers" test case
... that was recently added in #1429 commit 9fc6a27b5c "expand: correctly handles non-macro nodes ...".

  - Rename 'macro-issue1403.rs' -> 'macro-issue1426.rs'.
  - Get rid of '-w'; expect diagnostic instead.
  - Get rid of debugging options not relevant here.
  - Get rid of explicit '-O1'; make it a "torture" test case.
  - Replace always-matching 'scan-assembler "14"' ("14" appears in the crate name) with directed dump scanning.
      - ..., just not for '-O0', where such optimization is not done.
2022-08-06 13:16:31 +02:00
bors[bot] 7beea479c5
Merge #1437
1437: Array index access does not need to unsize to a slice for access r=philberty a=philberty

When we define the core code for SliceIndex access its possible for an
array to be fully coerced into a slice DST and follow the normal slice
index access which removes support for GCC -Warray-index checks and
generates unnessecary code for array access.

Fixes #1436

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-08-05 13:38:37 +00:00
Philip Herron c86ac620c2 Array index access does not need to unsize to a slice for access
When we define the core code for SliceIndex access its possible for an
array to be fully coerced into a slice DST and follow the normal slice
index access which removes support for GCC -Warray-index checks and
generates unnessecary code for array access.

Fixes #1436
2022-08-05 14:37:41 +01:00
bors[bot] 8725e324aa
Merge #1435
1435: Update the type hasher to stop duplication of aggregate types r=philberty a=philberty

The hasher we ported was always calling TYPE_HASH which ends up with
DECL_UID which is geneated causing aggregate types keep having a unique
hash which ends up confusing the middle end as two copy's of the same
aggegate type ends up making GCC think there is some kind of type
conversion required here.

Fixes #1434

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-08-05 12:42:24 +00:00
Philip Herron f70783d063 Update the type hasher to stop duplication of aggregate types
The hasher we ported was always calling TYPE_HASH which ends up with
DECL_UID which is geneated causing aggregate types keep having a unique
hash which ends up confusing the middle end as two copy's of the same
aggegate type ends up making GCC think there is some kind of type
conversion required here.

Fixes #1434
2022-08-05 13:03:01 +01:00
bors[bot] a39108dea1
Merge #1431
1431: Incremental refactor for better coercion site support r=philberty a=philberty

This is the major refactor to get our coercion site code closer to Rustc.
It introduced several new pieces most notably a refactor to the autoderef
cycle so this can be reused in method resolution and in coercion sites which
allows us to handle deref coercions. It will eventually allow us to get rid
of our bad implementation in rust-tyty-coercion.h which is just messy now.

Fixes #1198 

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-08-05 10:09:20 +00:00
bors[bot] e77bc10ba1
Merge #1433
1433: Fix bad transmute for aggregate types r=philberty a=philberty

This changes the CONVERT_EXPR to use the same ```*(foo*)&bar``` style cast from
the c front-end to handle the case of:
```
  int a[1];
  int b = (int)a;
```
Which is converted into:
```
  int b = *(int*)&a;
```
which the constant folders can turn directly into int b = a[0];

Fixes #1432


Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-08-05 09:33:52 +00:00
bors[bot] bc65cac0e7
Merge #1430
1430: hir: more conformant builtin macro detection r=philberty a=liushuyu

- hir: more conformant builtin macro detection

Fixes #971 

Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-08-04 19:47:43 +00:00
Philip Herron 7022b9dd10 Fix bad transmute for aggregate types
This changes the CONVERT_EXPR to use the same *(foo*)&bar style cast from
the c front-end to handle the case of:

  int a[1];
  int b = (int)a;

Which is converted into:

  int b = *(int*)&a;

which the constant folders can turn directly into int b = a[0];

Fixes #1432
2022-08-04 20:36:46 +01:00
Philip Herron 5d17a8b6b2 Support Autoderef coercions
This is an incremental approach to get our coercion sites more acurate to
rustc. This allows us to support coercions which require a deref by sharing
the code from the autoderef cycle. The eventual goal here will allow us to
remove the rust-tyty-coercion rules which is messy and cannot handle logic
such as DST's very well.

Fixes #1198
2022-08-04 16:52:52 +01:00
Philip Herron 79d0f29464 Fix ICE in audodref mappings when argument is a method call
Similar to the fix in 405d9f1d13 when we have
arguments that our method calls. The id used for storing the autoderef
mappings being the method call itself rather than the receiver argument
it will cause an ICE when we are type checking all arguments for the case
of:

  Foo(a, bar.baz(123))

This ensures we store the autoderef mappings directly on the reciever
instead.
2022-08-04 16:52:52 +01:00
Philip Herron 6f88307147 Refactor type resolution of method call expression
This simply moves the implementation of this into a cc file to help with
compilation times.
2022-08-04 16:52:29 +01:00
Philip Herron da31b651da Update TyTy::can_eq interface for pointers and references
It is valid for pointers and references to unify against inference
variables.
2022-08-04 16:52:29 +01:00
Philip Herron 405d9f1d13 Fix ICE with duplicate hirid on autoderef coercion site mappings
Imagine the call expression:

  Foo(a+b)

But the a+b is an operator overload of the assignment operation. We store
the autoderef coercions on the HIR id of the plus_expression here which is
going to conflict with the id used to store the autoderef coercions the
argument a+b. So this patch changes that all autoderef coercions store the
autoderef for the implicit method call on the hirid of the lvalue hirid
which in this case is 'a'. This means we won't conflict and cause an ICE
in this case.
2022-08-04 15:48:37 +01:00
Philip Herron 94e53f8e55 Refactor indirect_expression from the gcc-backend wrapper
This brings out the indirect expression out of our gcc wrapper, it also
just simplifies down to the normal build_indirect_expr_loc calls. Which
does not require specifiying the type since we can reuse TREE_TYPE. This
also simplifies the address_expression to just address_expr_with_loc and
grabs the type from TREE_TYPE as well.
2022-08-04 15:48:37 +01:00
Philip Herron 2dc902baa1 Refactor all coercion type calls into a single coercion_site function
In order to fully support coercion sites we need a single place in order to
implement the logic. This refactors all the coercion calls to have a single
TypeCheckBase::coercion_site(lhs, rhs, location). Eventually we will do
something similar for unifications and casts so we can improve our
diagnostics.
2022-08-04 15:48:36 +01:00
Philip Herron ffb419d6a4 Refactor the autoderef cycle to be a reuseable base class
The autoderef cycle is used to coerce/select apropriate methods during
method resolution. This same cycle of autoderef is also used as coercion
sites. In order to avoid duplicating the logic this extracts out a useful
base class that can be implemented to support this elsewhere.
2022-08-04 15:48:36 +01:00
liushuyu 8141f618bb
tree-wide(testsuite): update all the builtin macro tests ...
... now builtin macros need #[rustc_builtin_macro] annotation
2022-08-03 20:22:22 -06:00
liushuyu df1a201190 hir: more conformant builtin macro detection ...
... a macro is now considered builtin macro only if it has
rustc_builtin_macro attribute. This also allows overriding macro
definition with the same name as the builtin ones.

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-08-03 20:22:11 -06:00
bors[bot] c788a80619
Merge #1429
1429: expand: correctly handles non-macro nodes r=philberty a=liushuyu

- expand: correctly handles non-macro nodes when expanding macros recursively to avoid improperly stripping them

Fixes #1426

Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-08-03 09:18:41 +00:00
liushuyu 9fc6a27b5c
expand: correctly handles non-macro nodes ...
... when expanding macros recursively to avoid improperly stripping them

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-08-02 02:19:18 -06:00
bors[bot] 8809ee8c6a
Merge #1427
1427: unsafe: Check for unsafe function/method calls r=CohenArthur a=CohenArthur

Addresses #1411 

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-07-29 16:27:22 +00:00
Arthur Cohen f742538d13 unsafe: Report errors on calls to unsafe or extern functions and methods 2022-07-29 18:18:54 +02:00
Arthur Cohen b38dee3d38 mappings: Keep track of extern blocks
When inserting external items, it's interesting to also be able to
lookup the extern block they were defined in, similarly to impl items.
This is useful to know the ABI or other specifiers of the block the item
has been declared in.
2022-07-29 18:18:54 +02:00
Arthur Cohen e88a55ab69 testsuite: Calls to printf are unsafe 2022-07-29 18:18:54 +02:00
Arthur Cohen df0dd17b89 testsuite: Calls to transmute are unsafe 2022-07-29 18:18:54 +02:00
bors[bot] 2d824b796c
Merge #1421
1421: expand: further improves the handling of recursive macros r=CohenArthur a=liushuyu

- expand: further improves the handling of recursive macros.
Now all the attribute visitor that expands the macro fragment will recursively expand the macro using the unified expanding function `expand_macro_fragment_recursive` instead of expanding the fragment only once.

Fixes #1403 

Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-07-29 12:32:30 +00:00
bors[bot] 7f1685d7f6
Merge #1402
1402: CI Improvements and fixes r=philberty a=liushuyu

- CI: fix Remark check (fix #1340)


Co-authored-by: liushuyu <liushuyu011@gmail.com>
2022-07-29 11:18:16 +00:00
liushuyu 5e63ca064a
expand: further improves the handling of recursive macros ...
... now all the attribute visitor that expands the
macro fragment will recursively expand the macro
using the unified expanding function
`expand_macro_fragment_recursive` instead of expanding
the fragment only once.

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2022-07-28 23:29:31 -06:00