From 236a0b4ffb79854546b9f437499092cec23a5725 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 12 Dec 2024 11:31:49 -0800 Subject: [PATCH] spec: explain function invocation and passing of parameters more precisely - Describe that function invocation allocates space for a functions' variables. - Explain parameter passing in terms of assignments. Change-Id: Ia693d73a570f7d1aa2ac05e6095b4e602e4e9bf2 Reviewed-on: https://go-review.googlesource.com/c/go/+/635800 Reviewed-by: Robert Griesemer Reviewed-by: Ian Lance Taylor TryBot-Bypass: Robert Griesemer Auto-Submit: Robert Griesemer Reviewed-by: Rob Pike --- doc/go_spec.html | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 282f6cde0c..fff489c33a 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -2819,7 +2819,7 @@ values or variables, or components of other, non-interface types.

A type argument T satisfies a type constraint C -if T is an element of the type set defined by C; i.e., +if T is an element of the type set defined by C; in other words, if T implements C. As an exception, a strictly comparable type constraint may also be satisfied by a comparable @@ -4229,8 +4229,7 @@ calls f with arguments a1, a2, … an. Except for one special case, arguments must be single-valued expressions assignable to the parameter types of F and are evaluated before the function is called. -The type of the expression is the result type -of F. +The type of the expression is the result type of F. A method invocation is similar but the method itself is specified as a selector upon a value of the receiver type for the method. @@ -4251,9 +4250,14 @@ or used as a function value.

In a function call, the function value and arguments are evaluated in the usual order. -After they are evaluated, the parameters of the call are passed by value to the function +After they are evaluated, new storage is allocated for the function's +variables, which includes its parameters +and results. +Then, the arguments of the call are passed to the function, +which means that they are assigned +to their corresponding function parameters, and the called function begins execution. -The return parameters of the function are passed by value +The return parameters of the function are passed back to the caller when the function returns.

@@ -4267,9 +4271,9 @@ As a special case, if the return values of a function or method g are equal in number and individually assignable to the parameters of another function or method f, then the call f(g(parameters_of_g)) -will invoke f after binding the return values of -g to the parameters of f in order. The call -of f must contain no parameters other than the call of g, +will invoke f after passing the return values of +g to the parameters of f in order. +The call of f must contain no parameters other than the call of g, and g must have at least one return value. If f has a final ... parameter, it is assigned the return values of g that remain after @@ -4315,7 +4319,7 @@ If f is variadic with a final parameter p of type ...T, then within f the type of p is equivalent to type []T. If f is invoked with no actual arguments for p, -the value passed to p is nil. +the value passed to p is nil. Otherwise, the value passed is a new slice of type []T with a new underlying array whose successive elements are the actual arguments, which all must be assignable -- 2.48.1