From 9ee71a11393de9ebb1eb4a43dbebdea2def182f0 Mon Sep 17 00:00:00 2001 From: George Grec Date: Wed, 23 Oct 2024 20:33:14 +0200 Subject: [PATCH] refactor: replace "spread" with "record update" naming (gh-3737) --- compiler-core/src/ast.rs | 2 +- compiler-core/src/ast/typed.rs | 6 ++-- compiler-core/src/ast/untyped.rs | 2 +- compiler-core/src/ast/visit.rs | 12 ++++---- compiler-core/src/ast_folder.rs | 14 ++++----- compiler-core/src/call_graph.rs | 4 +-- compiler-core/src/erlang.rs | 6 ++-- compiler-core/src/erlang/tests/pipes.rs | 2 +- ..._tests__pipes__pipe_in_record_update.snap} | 0 compiler-core/src/format.rs | 10 +++---- compiler-core/src/javascript/expression.rs | 2 +- compiler-core/src/parse.rs | 8 ++--- compiler-core/src/type_/expression.rs | 30 +++++++++---------- 13 files changed, 49 insertions(+), 49 deletions(-) rename compiler-core/src/erlang/tests/snapshots/{gleam_core__erlang__tests__pipes__pipe_in_spread.snap => gleam_core__erlang__tests__pipes__pipe_in_record_update.snap} (100%) diff --git a/compiler-core/src/ast.rs b/compiler-core/src/ast.rs index 24c62593c6c..33cf3d48ed3 100644 --- a/compiler-core/src/ast.rs +++ b/compiler-core/src/ast.rs @@ -1286,7 +1286,7 @@ impl HasLocation for CallArg { } #[derive(Debug, Clone, PartialEq, Eq)] -pub struct RecordUpdateSpread { +pub struct RecordBeingUpdated { pub base: Box, pub location: SrcSpan, } diff --git a/compiler-core/src/ast/typed.rs b/compiler-core/src/ast/typed.rs index a3766a0e622..7830660d073 100644 --- a/compiler-core/src/ast/typed.rs +++ b/compiler-core/src/ast/typed.rs @@ -135,7 +135,7 @@ pub enum TypedExpr { RecordUpdate { location: SrcSpan, type_: Arc, - spread: Box, + record: Box, args: Vec, }, @@ -281,10 +281,10 @@ impl TypedExpr { .find_map(|arg| arg.find_node(byte_index)) .or_else(|| self.self_if_contains_location(byte_index)), - Self::RecordUpdate { spread, args, .. } => args + Self::RecordUpdate { record, args, .. } => args .iter() .find_map(|arg| arg.find_node(byte_index)) - .or_else(|| spread.find_node(byte_index)) + .or_else(|| record.find_node(byte_index)) .or_else(|| self.self_if_contains_location(byte_index)), } } diff --git a/compiler-core/src/ast/untyped.rs b/compiler-core/src/ast/untyped.rs index f45399090bb..873a62f9c0c 100644 --- a/compiler-core/src/ast/untyped.rs +++ b/compiler-core/src/ast/untyped.rs @@ -114,7 +114,7 @@ pub enum UntypedExpr { RecordUpdate { location: SrcSpan, constructor: Box, - spread: RecordUpdateSpread, + record: RecordBeingUpdated, arguments: Vec, }, diff --git a/compiler-core/src/ast/visit.rs b/compiler-core/src/ast/visit.rs index 23ce2b9fbbb..d3e0ad537d7 100644 --- a/compiler-core/src/ast/visit.rs +++ b/compiler-core/src/ast/visit.rs @@ -264,10 +264,10 @@ pub trait Visit<'ast> { &mut self, location: &'ast SrcSpan, type_: &'ast Arc, - spread: &'ast TypedExpr, + record: &'ast TypedExpr, args: &'ast [TypedRecordUpdateArg], ) { - visit_typed_expr_record_update(self, location, type_, spread, args); + visit_typed_expr_record_update(self, location, type_, record, args); } fn visit_typed_expr_negate_bool(&mut self, location: &'ast SrcSpan, value: &'ast TypedExpr) { @@ -714,9 +714,9 @@ where TypedExpr::RecordUpdate { location, type_, - spread, + record, args, - } => v.visit_typed_expr_record_update(location, type_, spread, args), + } => v.visit_typed_expr_record_update(location, type_, record, args), TypedExpr::NegateBool { location, value } => { v.visit_typed_expr_negate_bool(location, value) } @@ -970,12 +970,12 @@ pub fn visit_typed_expr_record_update<'a, V>( v: &mut V, _location: &'a SrcSpan, _typ: &'a Arc, - spread: &'a TypedExpr, + record: &'a TypedExpr, args: &'a [TypedRecordUpdateArg], ) where V: Visit<'a> + ?Sized, { - v.visit_typed_expr(spread); + v.visit_typed_expr(record); for arg in args { v.visit_typed_record_update_arg(arg); } diff --git a/compiler-core/src/ast_folder.rs b/compiler-core/src/ast_folder.rs index 95a024a90ff..c46a2ca1ed6 100644 --- a/compiler-core/src/ast_folder.rs +++ b/compiler-core/src/ast_folder.rs @@ -5,7 +5,7 @@ use crate::{ analyse::Inferred, ast::{ AssignName, Assignment, BinOp, CallArg, Constant, Definition, FunctionLiteralKind, Pattern, - RecordUpdateSpread, SrcSpan, Statement, TargetedDefinition, TodoKind, TypeAst, + RecordBeingUpdated, SrcSpan, Statement, TargetedDefinition, TodoKind, TypeAst, TypeAstConstructor, TypeAstFn, TypeAstHole, TypeAstTuple, TypeAstVar, UntypedArg, UntypedAssignment, UntypedClause, UntypedConstant, UntypedConstantBitArraySegment, UntypedCustomType, UntypedDefinition, UntypedExpr, UntypedExprBitArraySegment, @@ -320,9 +320,9 @@ pub trait UntypedExprFolder: TypeAstFolder + UntypedConstantFolder + PatternFold UntypedExpr::RecordUpdate { location, constructor, - spread, + record, arguments, - } => self.fold_record_update(location, constructor, spread, arguments), + } => self.fold_record_update(location, constructor, record, arguments), UntypedExpr::NegateBool { location, value } => self.fold_negate_bool(location, value), @@ -522,7 +522,7 @@ pub trait UntypedExprFolder: TypeAstFolder + UntypedConstantFolder + PatternFold UntypedExpr::RecordUpdate { location, constructor, - spread, + record, arguments, } => { let constructor = Box::new(self.fold_expr(*constructor)); @@ -536,7 +536,7 @@ pub trait UntypedExprFolder: TypeAstFolder + UntypedConstantFolder + PatternFold UntypedExpr::RecordUpdate { location, constructor, - spread, + record, arguments, } } @@ -800,13 +800,13 @@ pub trait UntypedExprFolder: TypeAstFolder + UntypedConstantFolder + PatternFold &mut self, location: SrcSpan, constructor: Box, - spread: RecordUpdateSpread, + record: RecordBeingUpdated, arguments: Vec, ) -> UntypedExpr { UntypedExpr::RecordUpdate { location, constructor, - spread, + record, arguments, } } diff --git a/compiler-core/src/call_graph.rs b/compiler-core/src/call_graph.rs index 91944ec1a3b..c860d4fdb63 100644 --- a/compiler-core/src/call_graph.rs +++ b/compiler-core/src/call_graph.rs @@ -251,9 +251,9 @@ impl<'a> CallGraphBuilder<'a> { } UntypedExpr::RecordUpdate { - spread, arguments, .. + record, arguments, .. } => { - self.expression(&spread.base); + self.expression(&record.base); for argument in arguments { self.expression(&argument.value); } diff --git a/compiler-core/src/erlang.rs b/compiler-core/src/erlang.rs index 70e987770c1..85e9abb5ef8 100644 --- a/compiler-core/src/erlang.rs +++ b/compiler-core/src/erlang.rs @@ -1656,11 +1656,11 @@ fn docs_args_call<'a>( } fn record_update<'a>( - spread: &'a TypedExpr, + record: &'a TypedExpr, args: &'a [TypedRecordUpdateArg], env: &mut Env<'a>, ) -> Document<'a> { - let expr_doc = maybe_block_expr(spread, env); + let expr_doc = maybe_block_expr(record, env); args.iter().fold(expr_doc, |tuple_doc, arg| { // Increment the index by 2, because the first element @@ -1844,7 +1844,7 @@ fn expr<'a>(expression: &'a TypedExpr, env: &mut Env<'a>) -> Document<'a> { TypedExpr::RecordAccess { record, index, .. } => tuple_index(record, index + 1, env), - TypedExpr::RecordUpdate { spread, args, .. } => record_update(spread, args, env), + TypedExpr::RecordUpdate { record, args, .. } => record_update(record, args, env), TypedExpr::Case { subjects, clauses, .. diff --git a/compiler-core/src/erlang/tests/pipes.rs b/compiler-core/src/erlang/tests/pipes.rs index 3c1e435b761..1c6a6f812cf 100644 --- a/compiler-core/src/erlang/tests/pipes.rs +++ b/compiler-core/src/erlang/tests/pipes.rs @@ -70,7 +70,7 @@ fn pipe_in_case_subject() { // https://github.com/gleam-lang/gleam/issues/1379 #[test] -fn pipe_in_spread() { +fn pipe_in_record_update() { assert_erl!( "pub type X { X(a: Int, b: Int) diff --git a/compiler-core/src/erlang/tests/snapshots/gleam_core__erlang__tests__pipes__pipe_in_spread.snap b/compiler-core/src/erlang/tests/snapshots/gleam_core__erlang__tests__pipes__pipe_in_record_update.snap similarity index 100% rename from compiler-core/src/erlang/tests/snapshots/gleam_core__erlang__tests__pipes__pipe_in_spread.snap rename to compiler-core/src/erlang/tests/snapshots/gleam_core__erlang__tests__pipes__pipe_in_record_update.snap diff --git a/compiler-core/src/format.rs b/compiler-core/src/format.rs index 13ba3ac870e..c7eae322ff5 100644 --- a/compiler-core/src/format.rs +++ b/compiler-core/src/format.rs @@ -1025,11 +1025,11 @@ impl<'comments> Formatter<'comments> { } UntypedExpr::RecordUpdate { constructor, - spread, + record, arguments: args, location, .. - } => self.record_update(constructor, spread, args, location), + } => self.record_update(constructor, record, args, location), }; commented(document, comments) } @@ -1334,14 +1334,14 @@ impl<'comments> Formatter<'comments> { pub fn record_update<'a>( &mut self, constructor: &'a UntypedExpr, - spread: &'a RecordUpdateSpread, + record: &'a RecordBeingUpdated, args: &'a [UntypedRecordUpdateArg], location: &SrcSpan, ) -> Document<'a> { use std::iter::once; let constructor_doc = self.expr(constructor); - let comments = self.pop_comments(spread.base.location().start); - let spread_doc = commented("..".to_doc().append(self.expr(&spread.base)), comments); + let comments = self.pop_comments(record.base.location().start); + let spread_doc = commented("..".to_doc().append(self.expr(&record.base)), comments); let arg_docs = args .iter() .map(|a| self.record_update_arg(a).group()) diff --git a/compiler-core/src/javascript/expression.rs b/compiler-core/src/javascript/expression.rs index af082b5b0f9..0f2b6feb40f 100644 --- a/compiler-core/src/javascript/expression.rs +++ b/compiler-core/src/javascript/expression.rs @@ -165,7 +165,7 @@ impl<'module> Generator<'module> { TypedExpr::Fn { args, body, .. } => self.fn_(args, body), TypedExpr::RecordAccess { record, label, .. } => self.record_access(record, label), - TypedExpr::RecordUpdate { spread, args, .. } => self.record_update(spread, args), + TypedExpr::RecordUpdate { record, args, .. } => self.record_update(record, args), TypedExpr::Var { name, constructor, .. diff --git a/compiler-core/src/parse.rs b/compiler-core/src/parse.rs index 3502ec8e5f1..b91d25ae39d 100644 --- a/compiler-core/src/parse.rs +++ b/compiler-core/src/parse.rs @@ -58,8 +58,8 @@ use crate::analyse::Inferred; use crate::ast::{ Arg, ArgNames, AssignName, Assignment, AssignmentKind, BinOp, BitArrayOption, BitArraySegment, CallArg, Clause, ClauseGuard, Constant, CustomType, Definition, Function, FunctionLiteralKind, - HasLocation, Import, Module, ModuleConstant, Pattern, Publicity, RecordConstructor, - RecordConstructorArg, RecordUpdateSpread, SrcSpan, Statement, TargetedDefinition, TodoKind, + HasLocation, Import, Module, ModuleConstant, Pattern, Publicity, RecordBeingUpdated, + RecordConstructor, RecordConstructorArg, SrcSpan, Statement, TargetedDefinition, TodoKind, TypeAlias, TypeAst, TypeAstConstructor, TypeAstFn, TypeAstHole, TypeAstTuple, TypeAstVar, UnqualifiedImport, UntypedArg, UntypedClause, UntypedClauseGuard, UntypedConstant, UntypedDefinition, UntypedExpr, UntypedModule, UntypedPattern, UntypedRecordUpdateArg, @@ -845,7 +845,7 @@ where // Record update let base = self.expect_expression()?; let base_e = base.location().end; - let spread = RecordUpdateSpread { + let record = RecordBeingUpdated { base: Box::new(base), location: SrcSpan { start: dot_s, @@ -865,7 +865,7 @@ where expr = UntypedExpr::RecordUpdate { location: SrcSpan { start, end }, constructor: Box::new(expr), - spread, + record, arguments: args, }; } else { diff --git a/compiler-core/src/type_/expression.rs b/compiler-core/src/type_/expression.rs index cb7fbf3ff30..54b1cc7f416 100644 --- a/compiler-core/src/type_/expression.rs +++ b/compiler-core/src/type_/expression.rs @@ -4,7 +4,7 @@ use crate::{ ast::{ Arg, Assignment, AssignmentKind, BinOp, BitArrayOption, BitArraySegment, CallArg, Clause, ClauseGuard, Constant, FunctionLiteralKind, HasLocation, ImplicitCallArgOrigin, Layer, - RecordUpdateSpread, SrcSpan, Statement, TodoKind, TypeAst, TypedArg, TypedAssignment, + RecordBeingUpdated, SrcSpan, Statement, TodoKind, TypeAst, TypedArg, TypedAssignment, TypedClause, TypedClauseGuard, TypedConstant, TypedExpr, TypedMultiPattern, TypedStatement, UntypedArg, UntypedAssignment, UntypedClause, UntypedClauseGuard, UntypedConstant, UntypedConstantBitArraySegment, UntypedExpr, UntypedExprBitArraySegment, @@ -394,9 +394,9 @@ impl<'a, 'b> ExprTyper<'a, 'b> { UntypedExpr::RecordUpdate { location, constructor, - spread, + record, arguments: args, - } => self.infer_record_update(*constructor, spread, args, location), + } => self.infer_record_update(*constructor, record, args, location), UntypedExpr::NegateBool { location, value } => self.infer_negate_bool(location, *value), @@ -2295,7 +2295,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { fn infer_record_update( &mut self, constructor: UntypedExpr, - spread: RecordUpdateSpread, + record: RecordBeingUpdated, args: Vec, location: SrcSpan, ) -> Result { @@ -2361,12 +2361,12 @@ impl<'a, 'b> ExprTyper<'a, 'b> { } }; - let spread = self.infer(*spread.base)?; + let record = self.infer(*record.base)?; let return_type = self.instantiate(retrn.clone(), &mut hashmap![]); - // Check that the spread variable unifies with the return type of the constructor - unify(return_type, spread.type_()) - .map_err(|e| convert_unify_error(e, spread.location()))?; + // Check that the record variable unifies with the return type of the constructor + unify(return_type, record.type_()) + .map_err(|e| convert_unify_error(e, record.location()))?; let args: Vec = args .iter() @@ -2377,18 +2377,18 @@ impl<'a, 'b> ExprTyper<'a, 'b> { location, }| { let value = self.infer(value.clone())?; - let spread_field = self.infer_known_record_expression_access( - spread.clone(), + let record_field = self.infer_known_record_expression_access( + record.clone(), label.clone(), *location, FieldAccessUsage::Other, )?; // Check that the update argument unifies with the corresponding - // field in the record contained within the spread variable. We - // need to check the spread, and not the constructor, in order + // field in the record contained within the record variable. We + // need to check the record, and not the constructor, in order // to handle polymorphic types. - unify(spread_field.type_(), value.type_()) + unify(record_field.type_(), value.type_()) .map_err(|e| convert_unify_error(e, value.location()))?; match field_map.fields.get(label) { @@ -2418,8 +2418,8 @@ impl<'a, 'b> ExprTyper<'a, 'b> { Ok(TypedExpr::RecordUpdate { location, - type_: spread.type_(), - spread: Box::new(spread), + type_: record.type_(), + record: Box::new(record), args, }) }