Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
m new committed Oct 7, 2022
1 parent 8143b75 commit 1eefc1a
Show file tree
Hide file tree
Showing 17 changed files with 212 additions and 25 deletions.
80 changes: 67 additions & 13 deletions explorer/interpreter/type_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2671,10 +2671,8 @@ auto TypeChecker::TypeCheckTypeExp(Nonnull<Expression*> type_expression,
const ImplScope& impl_scope, bool concrete)
-> ErrorOr<Nonnull<const Value*>> {
CARBON_RETURN_IF_ERROR(TypeCheckExp(type_expression, impl_scope));
llvm::outs()<<type_expression->static_type()<<"\n";

CARBON_ASSIGN_OR_RETURN(Nonnull<const Value*> type,
InterpExp(type_expression, arena_, trace_stream_));
CARBON_ASSIGN_OR_RETURN( Nonnull<const Value*> type,
InterpExp(type_expression, arena_, trace_stream_));
CARBON_RETURN_IF_ERROR(
concrete ? ExpectIsConcreteType(type_expression->source_loc(), type)
: ExpectIsType(type_expression->source_loc(), type));
Expand All @@ -2685,8 +2683,68 @@ auto TypeChecker::TypeCheckTypeReturnDeclExp(Nonnull<Expression*> type_expressio
const ImplScope& impl_scope)
-> ErrorOr<Nonnull<const Value*>> {
CARBON_RETURN_IF_ERROR(TypeCheckExp(type_expression, impl_scope));
CARBON_RETURN_IF_ERROR(ExpectIsType(type_expression->source_loc(), &type_expression->static_type()));
return &type_expression->static_type();
Nonnull<const Value*> type;
if(type_expression->kind() == ExpressionKind::CallExpression){
type = &type_expression->static_type();
switch(type->kind()){
case Value::Kind::IntValue:
case Value::Kind::BoolValue:
case Value::Kind::FunctionValue:
case Value::Kind::DestructorValue:
case Value::Kind::BoundMethodValue:
case Value::Kind::PointerValue:
case Value::Kind::LValue:
case Value::Kind::StructValue:
case Value::Kind::NominalClassValue:
case Value::Kind::TupleValue:
case Value::Kind::UninitializedValue:
case Value::Kind::BindingPlaceholderValue:
case Value::Kind::AddrValue:
case Value::Kind::ContinuationValue:
case Value::Kind::StringValue:
case Value::Kind::AlternativeValue:
case Value::Kind::AlternativeConstructorValue:
break;
case Value::Kind::ImplWitness:
case Value::Kind::BindingWitness:
case Value::Kind::ConstraintWitness:
case Value::Kind::ConstraintImplWitness:
case Value::Kind::IntType:
case Value::Kind::BoolType:
case Value::Kind::TypeType:
case Value::Kind::FunctionType:
case Value::Kind::PointerType:
case Value::Kind::AutoType:
case Value::Kind::StructType:
case Value::Kind::NominalClassType:
case Value::Kind::MixinPseudoType:
case Value::Kind::InterfaceType:
case Value::Kind::ConstraintType:
case Value::Kind::ContinuationType:
case Value::Kind::VariableType:
case Value::Kind::AssociatedConstant:
case Value::Kind::ParameterizedEntityName:
case Value::Kind::MemberName:
case Value::Kind::StringType:
case Value::Kind::TypeOfClassType:
case Value::Kind::TypeOfMixinPseudoType:
case Value::Kind::TypeOfInterfaceType:
case Value::Kind::TypeOfConstraintType:
case Value::Kind::TypeOfParameterizedEntityName:
case Value::Kind::TypeOfMemberName:
case Value::Kind::StaticArrayType:
case Value::Kind::ChoiceType:
case Value::Kind::TypeOfChoiceType:
CARBON_ASSIGN_OR_RETURN(type,
InterpExp(type_expression, arena_, trace_stream_));
break;
}
}else {
CARBON_ASSIGN_OR_RETURN(type,
InterpExp(type_expression, arena_, trace_stream_));
}
CARBON_RETURN_IF_ERROR(ExpectIsType(type_expression->source_loc(), type));
return type;
}

auto TypeChecker::TypeCheckWhereClause(Nonnull<WhereClause*> clause,
Expand Down Expand Up @@ -3275,13 +3333,12 @@ auto TypeChecker::DeclareCallableDeclaration(Nonnull<CallableDeclaration*> f,
// new types into scope.
// Should we be doing SetConstantValue instead? -Jeremy
// And shouldn't the type of this be Type?
llvm::outs()<<"HAZEL 1"<<"\n";
CARBON_ASSIGN_OR_RETURN(Nonnull<const Value*> ret_type,
TypeCheckTypeReturnDeclExp(*return_expression, function_scope));



llvm::outs()<<"HAZEL 2"<<"\n";
//CARBON_ASSIGN_OR_RETURN(Nonnull<const Value*> ret_type,
// TypeCheckTypeExp(*return_expression, function_scope,
// /*concrete=*/false));

f->return_term().set_static_type(ret_type);
} else if (f->return_term().is_omitted()) {
Expand Down Expand Up @@ -4110,12 +4167,10 @@ auto TypeChecker::TypeCheck(AST& ast) -> ErrorOr<Success> {
ImplScope impl_scope;
ScopeInfo top_level_scope_info = ScopeInfo::ForNonClassScope(&impl_scope);
for (Nonnull<Declaration*> declaration : ast.declarations) {
llvm::outs()<<"declaration:"<<*declaration<<"\n";
CARBON_RETURN_IF_ERROR(
DeclareDeclaration(declaration, top_level_scope_info));
}
for (Nonnull<Declaration*> decl : ast.declarations) {
llvm::outs()<<"Test:"<<*decl<<"\n";
CARBON_RETURN_IF_ERROR(
TypeCheckDeclaration(decl, impl_scope, std::nullopt));
// Check to see if this declaration is a builtin.
Expand Down Expand Up @@ -4217,7 +4272,6 @@ auto TypeChecker::DeclareDeclaration(Nonnull<Declaration*> d,
}
case DeclarationKind::FunctionDeclaration: {
auto& func_def = cast<CallableDeclaration>(*d);
llvm::outs()<<"Func"<<"\n";
CARBON_RETURN_IF_ERROR(DeclareCallableDeclaration(&func_def, scope_info));
break;
}
Expand Down
4 changes: 4 additions & 0 deletions explorer/testdata/array/fail_index.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
// RUN: %{not} %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s
// CHECK: 921
// CHECK: 922 x[2]
// CHECK: (0, 1)
// CHECK: 924

package ExplorerTest api;

Expand Down
8 changes: 8 additions & 0 deletions explorer/testdata/array/index.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s
// CHECK: 921
// CHECK: 922 x[0]
// CHECK: (0, 0)
// CHECK: 924
// CHECK: 921
// CHECK: 922 x[1]
// CHECK: (0, 0)
// CHECK: 924
// CHECK: result: 0

package ExplorerTest api;
Expand Down
8 changes: 8 additions & 0 deletions explorer/testdata/array/nested.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s
// CHECK: 921
// CHECK: 922 x[1]
// CHECK: ((0, 1, 2), (3, 4, 5))
// CHECK: 924
// CHECK: 921
// CHECK: 922 x[1][2]
// CHECK: (3, 4, 5)
// CHECK: 924
// CHECK: result: 0

package ExplorerTest api;
Expand Down
4 changes: 4 additions & 0 deletions explorer/testdata/class/method_call_method.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s
// CHECK: 921
// CHECK: 922 p.GetXY()[0]
// CHECK: (0, 0)
// CHECK: 924
// CHECK: result: 0

package ExplorerTest api;
Expand Down
12 changes: 0 additions & 12 deletions explorer/testdata/crash/issue-1394

This file was deleted.

21 changes: 21 additions & 0 deletions explorer/testdata/crash/issue-1394.carbon
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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
//
// RUN: %{not} %{explorer} %s 2>&1 2>&1 | %{FileCheck} %s
// AUTOUPDATE: %{explorer} %s

package EmptyIdentifier impl;

fn apply[T:! Type, U:! Type](f: T, EmptyIdentifier: U)
{
// CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/crash/issue-1394.carbon:[[@LINE+1]]: expected a tuple
match (true[true]) {}
}

fn EmptyIdentifier() -> apply(true, true);

fn Main() -> i32 {
return 0;
}

16 changes: 16 additions & 0 deletions explorer/testdata/function/type_match.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s
// CHECK: 921
// CHECK: 922 t[0]
// CHECK: ((1, 2), (3, 4))
// CHECK: 924
// CHECK: 921
// CHECK: 922 t[0][0]
// CHECK: (1, 2)
// CHECK: 924
// CHECK: 921
// CHECK: 922 t[1]
// CHECK: ((1, 2), (3, 4))
// CHECK: 924
// CHECK: 921
// CHECK: 922 t[1][1]
// CHECK: (3, 4)
// CHECK: 924
// CHECK: result: 0

package ExplorerTest api;
Expand Down
12 changes: 12 additions & 0 deletions explorer/testdata/generic_function/implicit_conversion.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s
// CHECK: 921
// CHECK: 922 x.b[0]
// CHECK: ({.m = 2, .n = 1}, 3)
// CHECK: 924
// CHECK: 921
// CHECK: 922 x.b[0]
// CHECK: ({.m = 2, .n = 1}, 3)
// CHECK: 924
// CHECK: 921
// CHECK: 922 x.b[1]
// CHECK: ({.m = 2, .n = 1}, 3)
// CHECK: 924
// CHECK: result: 4213

package ExplorerTest api;
Expand Down
12 changes: 12 additions & 0 deletions explorer/testdata/generic_function/swap.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s
// CHECK: 921
// CHECK: 922 tuple[1]
// CHECK: (0, true)
// CHECK: 924
// CHECK: 921
// CHECK: 922 tuple[0]
// CHECK: (0, true)
// CHECK: 924
// CHECK: 921
// CHECK: 922 swap((0, true))[1]
// CHECK: (true, 0)
// CHECK: 924
// CHECK: result: 0

package ExplorerTest api;
Expand Down
12 changes: 12 additions & 0 deletions explorer/testdata/generic_function/tuple_map.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s
// CHECK: 921
// CHECK: 922 tuple[0]
// CHECK: (0, 2)
// CHECK: 924
// CHECK: 921
// CHECK: 922 tuple[1]
// CHECK: (0, 2)
// CHECK: 924
// CHECK: 921
// CHECK: 922 map(inc, (0, 2))[0]
// CHECK: (1, 3)
// CHECK: 924
// CHECK: result: 1

package ExplorerTest api;
Expand Down
8 changes: 8 additions & 0 deletions explorer/testdata/interface/tuple_vector_add_scale.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s
// CHECK: 921
// CHECK: 922 t[0]
// CHECK: (Point{.x = 1, .y = 1}, Point{.x = 2, .y = 3})
// CHECK: 924
// CHECK: 921
// CHECK: 922 t[1]
// CHECK: (Point{.x = 1, .y = 1}, Point{.x = 2, .y = 3})
// CHECK: 924
// CHECK: result: 0

package ExplorerTest api;
Expand Down
12 changes: 12 additions & 0 deletions explorer/testdata/tuple/ending_comma.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s
// CHECK: 921
// CHECK: 922 t1[0]
// CHECK: (5)
// CHECK: 924
// CHECK: 921
// CHECK: 922 t2[0]
// CHECK: (2, 3)
// CHECK: 924
// CHECK: 921
// CHECK: 922 t2[1]
// CHECK: (2, 3)
// CHECK: 924
// CHECK: result: 0

package ExplorerTest api;
Expand Down
4 changes: 4 additions & 0 deletions explorer/testdata/tuple/index.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s
// CHECK: 921
// CHECK: 922 x[0]
// CHECK: (0, 1)
// CHECK: 924
// CHECK: result: 0

package ExplorerTest api;
Expand Down
8 changes: 8 additions & 0 deletions explorer/testdata/tuple/match_nested.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s
// CHECK: 921
// CHECK: 922 c[0]
// CHECK: (3, 4)
// CHECK: 924
// CHECK: 921
// CHECK: 922 c[1]
// CHECK: (3, 4)
// CHECK: 924
// CHECK: result: 0

package ExplorerTest api;
Expand Down
8 changes: 8 additions & 0 deletions explorer/testdata/tuple/no_ending_comma.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s
// CHECK: 921
// CHECK: 922 t2[0]
// CHECK: (3, 2)
// CHECK: 924
// CHECK: 921
// CHECK: 922 t2[1]
// CHECK: (3, 2)
// CHECK: 924
// CHECK: result: 0

package ExplorerTest api;
Expand Down
8 changes: 8 additions & 0 deletions explorer/testdata/tuple/to_array.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// AUTOUPDATE: %{explorer} %s
// CHECK: 921
// CHECK: 922 a[0]
// CHECK: (1, 2)
// CHECK: 924
// CHECK: 921
// CHECK: 922 a[1]
// CHECK: (1, 2)
// CHECK: 924
// CHECK: result: 3

package ExplorerTest api;
Expand Down

0 comments on commit 1eefc1a

Please sign in to comment.