Switch GetNodeBlock and GetTypeBlock to return an ArrayRef (#3220)

This removes the risk of accidentally performing a vector copy when
calling these functions, and is a preparation step towards the new node
block allocation design.

This required changing how we build call expressions. Instead of
finishing the argument block and then later adding a return slot, we now
delay finishing the argument block and checking for conversions to
parameter types until after we've added the return slot to it.
This commit is contained in:
Richard Smith
2023-09-13 20:47:53 +00:00
committed by GitHub
parent a05018a6ba
commit d63fceff8e
8 changed files with 130 additions and 48 deletions
@@ -0,0 +1,27 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
fn Run() {
// CHECK:STDERR: fail_not_callable.carbon:[[@LINE+6]]:24: Semantics TODO: `Not a callable name`.
// CHECK:STDERR: var x: i32 = "hello"();
// CHECK:STDERR: ^
// CHECK:STDERR: fail_not_callable.carbon:[[@LINE+3]]:25: Cannot implicitly convert from `String` to `i32`.
// CHECK:STDERR: var x: i32 = "hello"();
// CHECK:STDERR: ^
var x: i32 = "hello"();
}
// CHECK:STDOUT: file "fail_not_callable.carbon" {
// CHECK:STDOUT: %.loc7 = fn_decl @Run
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Run() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %x: ref i32 = var "x"
// CHECK:STDOUT: %.loc14: String = string_literal "hello"
// CHECK:STDOUT: assign %x, <error>
// CHECK:STDOUT: return
// CHECK:STDOUT: }
@@ -81,6 +81,7 @@ fn Main() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %.loc18_8.1: i32 = int_literal 1
// CHECK:STDOUT: %.loc18_8.2: i32 = stub_reference %.loc18_8.1
// CHECK:STDOUT: %.loc18_7: type = tuple_type ()
// CHECK:STDOUT: %.loc25_8.1: i32 = int_literal 0
// CHECK:STDOUT: %.loc25_8.2: i32 = stub_reference %.loc25_8.1
// CHECK:STDOUT: %.loc25_11.1: i32 = int_literal 1
@@ -30,5 +30,6 @@ fn Main() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %.loc16_7.1: f64 = real_literal 10e-1
// CHECK:STDOUT: %.loc16_7.2: f64 = stub_reference %.loc16_7.1
// CHECK:STDOUT: %.loc16_6: type = tuple_type ()
// CHECK:STDOUT: return
// CHECK:STDOUT: }