-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is for the proposal, plus a few bug fixes that would/will be necessary when this is put into actual use. Fixes #66408. Updates #63131. Change-Id: I3a66e09d707dd579c59f155e7f53367f41214c30 Reviewed-on: https://go-review.googlesource.com/c/go/+/578355 Reviewed-by: Austin Clements <austin@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: David Chase <drchase@google.com>
- Loading branch information
Showing
11 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pkg structs, type HostLayout struct #66408 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
### New structs package | ||
|
||
|
||
The new [structs](/pkg/structs) package provides | ||
types for struct fields that modify properties of | ||
the containing struct type such as memory layout. | ||
|
||
In this release, the only such type is | ||
[`HostLayout`](/pkg/structs#HostLayout) | ||
which indicates that a structure with a field of that | ||
type has a layout that conforms to host platform | ||
expectations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!-- This is a new package; covered in 6-stdlib/3-structs.md. --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Package structs defines marker types that can be used as struct fields | ||
// to modify the properties of a struct. | ||
// | ||
// By convention, a marker type should be used as the type of a field | ||
// named "_", placed at the beginning of a struct type definition. | ||
package structs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package structs | ||
|
||
// HostLayout marks a struct as using host memory layout. A struct with a | ||
// field of type HostLayout will be laid out in memory according to host | ||
// expectations, generally following the host's C ABI. | ||
// | ||
// HostLayout does not affect layout within any other struct-typed fields | ||
// of the containing struct, nor does it affect layout of structs | ||
// containing the struct marked as host layout. | ||
// | ||
// By convention, HostLayout should be used as the type of a field | ||
// named "_", placed at the beginning of the struct type definition. | ||
type HostLayout struct { | ||
_ hostLayout // prevent accidental conversion with plain struct{} | ||
} | ||
|
||
// We use an unexported type within the exported type to give the marker | ||
// type itself, rather than merely its name, a recognizable identity in | ||
// the type system. The main consequence of this is that a user can give | ||
// the type a new name and it will still have the same properties, e.g., | ||
// | ||
// type HL structs.HostLayout | ||
// | ||
// It also prevents unintentional conversion of struct{} to a named marker type. | ||
type hostLayout struct { | ||
} |