Skip to content

Commit 00f1540

Browse files
fix: avoid Sorbet errors and improve consistency of database to avoid nil (riscv-software-src#722)
Fixes riscv-software-src#716
1 parent 013310e commit 00f1540

39 files changed

+106
-45
lines changed

.sorbet-config

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
--dir
2-
lib
3-
--dir
4-
sorbet/rbi
5-
--file
6-
Rakefile
7-
--file
8-
backends/ext_pdf_doc/idl_lexer.rb
9-
--file
10-
backends/cpp_hart_gen/lib/template_helpers.rb
2+
.
3+
--ignore
4+
ext
5+
--ignore
6+
.home/.gems
7+
--ignore
8+
node_modules

arch/manual/isa.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
$schema: manual_schema.json#
44
kind: manual
55
name: isa
6+
long_name: Entire RISC-V ISA
67
marketing_name: RISC-V ISA Manual
78
url: https://github.com/riscv/riscv-isa-manual
89
license:

arch/manual_version/isa/20240411/isa_20240411.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ kind: manual version
55
manual: { $ref: manual/isa.yaml# }
66
version: "4.0.0-pre"
77
name: "isa_20240411"
8+
long_name: "Release 20240411 of the RISC-V ISA Manuals"
89
marketing_version: "20240411"
910
state: "development"
1011
url: https://github.com/riscv/releases/tag/20240411

arch/profile/MP-S-64.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
$schema: profile_schema.json#
44
kind: profile
55
name: MP-S-64
6+
long_name: S-mode extensions for a Mock 64-bit Apps Processor profile
67
marketing_name: MockProfile 64-bit S-mode
78
description: This is the Mock Profile Supervisor Mode description.
89
mode: S

arch/profile/MP-U-64.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_schema.json#
22
kind: profile
33
name: MP-U-64
4+
long_name: U-mode extensions for a Mock 64-bit Apps Processor profile
45
marketing_name: MockProfile 64-bit Unpriv
56
mode: Unpriv
67
base: 64

arch/profile/RVA20S64.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_schema.json#
22
kind: profile
33
name: RVA20S64
4+
long_name: S-mode extensions for version 20 of the 64-bit Apps Processor profile
45
marketing_name: RVA20S64
56
mode: S
67
base: 64

arch/profile/RVA20U64.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_schema.json#
22
kind: profile
33
name: RVA20U64
4+
long_name: U-mode extensions for version 20 of the 64-bit Apps Processor profile
45
marketing_name: RVA20U64
56
mode: Unpriv
67
base: 64

arch/profile/RVA22S64.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_schema.json#
22
kind: profile
33
name: RVA22S64
4+
long_name: S-mode extensions for version 22 of the 64-bit Apps Processor profile
45
marketing_name: RVA22S64
56
mode: S
67
base: 64

arch/profile/RVA22U64.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_schema.json#
22
kind: profile
33
name: RVA22U64
4+
long_name: U-mode extensions for version 22 of the 64-bit Apps Processor profile
45
marketing_name: RVA22U64
56
mode: Unpriv
67
base: 64

arch/profile/RVA23M64.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_schema.json#
22
kind: profile
33
name: RVA23M64
4+
long_name: M-mode extensions for version 23 of the 64-bit Apps Processor profile (not ratified)
45
marketing_name: RVA23M64
56
mode: M
67
base: 64

arch/profile/RVA23S64.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_schema.json#
22
kind: profile
33
name: RVA23S64
4+
long_name: S-mode extensions for version 23 of the 64-bit Apps Processor profile
45
marketing_name: RVA23S64
56
mode: S
67
base: 64

arch/profile/RVA23U64.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_schema.json#
22
kind: profile
33
name: RVA23U64
4+
long_name: U-mode extensions for version 23 of the 64-bit Apps Processor profile
45
marketing_name: RVA23U64
56
mode: Unpriv
67
base: 64

arch/profile/RVB23M64.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_schema.json#
22
kind: profile
33
name: RVB23M64
4+
long_name: M-mode extensions for version 23 of the 64-bit Bespoke Apps Processor profile (not ratified)
45
marketing_name: RVB23M64
56
mode: M
67
base: 64

arch/profile/RVB23S64.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_schema.json#
22
kind: profile
33
name: RVB23S64
4+
long_name: S-mode extensions for version 23 of the 64-bit Bespoke Apps Processor profile
45
marketing_name: RVB23S64
56
mode: S
67
base: 64

arch/profile/RVB23U64.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_schema.json#
22
kind: profile
33
name: RVB23U64
4+
long_name: U-mode extensions for version 23 of the 64-bit Bespoke Apps Processor profile
45
marketing_name: RVB23U64
56
mode: Unpriv
67
base: 64

arch/profile/RVI20U32.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_schema.json#
22
kind: profile
33
name: RVI20U32
4+
long_name: U-mode extensions for version 20 of a 32-bit processor
45
marketing_name: RVI20U32
56
mode: Unpriv
67
base: 32

arch/profile/RVI20U64.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_schema.json#
22
kind: profile
33
name: RVI20U64
4+
long_name: U-mode extensions for version 20 of a 64-bit processor
45
$inherits: "profile/RVI20U32.yaml#"
56
base: 64
67
marketing_name: RVI20U64

arch/profile_class/Mock.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ $schema: profile_class_schema.json#
22
kind: profile class
33
processor_kind: Microcontroller
44
name: Mock
5+
long_name: Mock Profile Class
56
marketing_name: Mock Profile Class
67
introduction: Here's the Mock Profile Class introduction.
78
description: |

arch/profile_class/RVA.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ $schema: profile_class_schema.json#
44
kind: profile class
55
processor_kind: Apps Processor
66
name: RVA
7+
long_name: Apps Processor profile class for Rich Operating Systems requiring binary-compatibility
78
marketing_name: RVA
89
introduction: |
910
The RVA profile class targets application processors for markets

arch/profile_class/RVB.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ $schema: profile_class_schema.json#
22
kind: profile class
33
processor_kind: Apps Processor
44
name: RVB
5+
long_name: Apps Processor profile class for Bespoke Rich Operating System
56
marketing_name: RVB
67
introduction: |
78
The RVB profile class targets application processors for markets

arch/profile_class/RVI.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ $schema: profile_class_schema.json#
22
kind: profile class
33
processor_kind: Generic Unprivileged
44
name: RVI
5+
long_name: Unprivileged nstructions
56
marketing_name: RVI
67
introduction: The RVI profile class documents the initial set of unprivileged instructions.
78
description: |

arch/profile_release/Mock.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_release_schema.json#
22
kind: profile release
33
name: Mock
4+
long_name: Mock
45
marketing_name: Mock Profile Release Marketing Name
56
class:
67
$ref: profile_class/Mock.yaml#

arch/profile_release/RVA20.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_release_schema.json#
22
kind: profile release
33
name: RVA20
4+
long_name: RVA20
45
marketing_name: RVA20
56
class:
67
$ref: profile_class/RVA.yaml#

arch/profile_release/RVA22.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_release_schema.json#
22
kind: profile release
33
name: RVA22
4+
long_name: RVA22
45
marketing_name: RVA22
56
class:
67
$ref: profile_class/RVA.yaml#

arch/profile_release/RVA23.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_release_schema.json#
22
kind: profile release
33
name: RVA23
4+
long_name: RVA23
45
marketing_name: RVA23
56
class:
67
$ref: profile_class/RVA.yaml#

arch/profile_release/RVB23.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_release_schema.json#
22
kind: profile release
33
name: RVB23
4+
long_name: RVB23
45
marketing_name: RVB23
56
class:
67
$ref: profile_class/RVB.yaml#

arch/profile_release/RVI20.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$schema: profile_release_schema.json#
22
kind: profile release
33
name: RVI20
4+
long_name: RVI20
45
marketing_name: RVI20
56
class:
67
$ref: profile_class/RVI.yaml#
@@ -21,3 +22,5 @@ contributors:
2122
profiles:
2223
- { $ref: profile/RVI20U32.yaml# }
2324
- { $ref: profile/RVI20U64.yaml# }
25+
description: |
26+
This profile release defines the RISC-V base ISA unprivileged instructions.

lib/arch_obj_models/cert_test_procedure.rb

+30-15
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,43 @@
11
# frozen_string_literal: true
2+
# typed: true
3+
4+
require "sorbet-runtime"
25

36
class CertTestProcedure
7+
extend T::Sig
8+
9+
# @return [String] Unique ID of the test procedure
10+
sig { returns(String) }
11+
attr_reader :id
12+
13+
# Description of test procedure (could be multiple lines).
14+
sig { returns(String) }
15+
attr_reader :description
16+
17+
# What kind of database object is this?
18+
sig { returns(String) }
19+
attr_reader :kind
20+
21+
# Name of test file that implements this test procedure. Could be nil.
22+
sig { returns(T.nilable(String)) }
23+
attr_reader :test_file_name
24+
425
# @param data [Hash<String, Object>] Data from YAML file
526
# @param db_obj [DatabaseObject] Database object that defines test procedure (Extension, Instruction, CSR, or CSR field)
27+
sig {params(data: T::Hash[String, T.untyped], db_obj: T.any(Extension, Instruction, Csr, CsrField)).void }
628
def initialize(data, db_obj)
7-
raise ArgumentError, "Need Hash but was passed a #{data.class}" unless data.is_a?(Hash)
8-
raise ArgumentError, "Need DatabaseObject but was passed a #{db_obj.class}" unless db_obj.is_a?(DatabaseObject)
9-
1029
@data = data
1130
@db_obj = db_obj
1231

13-
raise ArgumentError, "Missing certification test procedure ID for #{db_obj.name} of kind #{db_obj.kind}" if id.nil?
14-
warn "Warning: Missing test_file_name for certification test procedure description for #{db_obj.name} of kind #{db_obj.kind}" if test_file_name.nil?
15-
raise ArgumentError, "Missing certification test procedure description for #{db_obj.name} of kind #{db_obj.kind}" if description.nil?
16-
end
17-
18-
# @return [String] Unique ID of the test procedure
19-
def id = @data["id"]
32+
@id = T.must_because(data["id"]) { pp data }
33+
@description = T.must_because(data["description"]) { pp data }
34+
@kind = T.must_because(db_obj.kind) { pp db_obj }
35+
@test_file_name = data["test_file_name"]
2036

21-
# @return [String] Name of test file that implements this test procedure. Could be nil.
22-
def test_file_name = @data["test_file_name"]
23-
24-
# @return [String] Description of test procedure (could be multiple lines)
25-
def description = @data["description"]
37+
if test_file_name.nil?
38+
warn "Warning: Missing test_file_name for certification test procedure description for ID #{id} of kind #{kind}"
39+
end
40+
end
2641

2742
# @return [Array<CertNormativeRule>]
2843
def cert_normative_rules

lib/arch_obj_models/csr_field.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ def base
3434
# @param field_data [Hash<String,Object>] Field data from the arch spec
3535
sig { params(parent_csr: Csr, field_name: String, field_data: T::Hash[String, T.untyped]).void }
3636
def initialize(parent_csr, field_name, field_data)
37+
field_data["name"] = field_name
38+
field_data["long_name"] = parent_csr.long_name + " #{field_name} field"
39+
field_data["kind"] = "csr_field"
3740
super(field_data, parent_csr.data_path, parent_csr.arch)
38-
@name = field_name
3941
@parent = parent_csr
4042
end
4143

lib/arch_obj_models/database_obj.rb

+8-7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ class ValidationError < ::StandardError
114114
sig { returns(String) }
115115
attr_reader :long_name
116116

117+
sig { returns(String) }
118+
attr_reader :kind
119+
117120
# @return [Architecture] If only a specification (no config) is known
118121
# @return [ConfiguredArchitecture] If a specification and config is known
119122
# @return [nil] If neither is known
@@ -132,9 +135,6 @@ def cfg_arch
132135
sig { returns(T::Boolean) }
133136
def cfg_arch? = !@cfg_arch.nil?
134137

135-
sig { returns(String) }
136-
def kind = @data["kind"]
137-
138138
@@schemas ||= {}
139139
@@schema_ref_resolver ||= proc do |pattern|
140140
if pattern.to_s =~ /^http/
@@ -299,16 +299,17 @@ def description(
299299

300300
# @param data [Hash<String,Object>] Hash with fields to be added
301301
# @param data_path [Pathname] Path to the data file
302-
sig { params(data: T::Hash[String, T.untyped], data_path: T.any(String, Pathname), arch: T.nilable(Architecture)).void }
302+
sig { params(data: T::Hash[String, T.untyped], data_path: T.any(String, Pathname), arch: Architecture).void }
303303
def initialize(data, data_path, arch)
304304
@data = data
305305
@data_path = Pathname.new(data_path)
306306
if arch.is_a?(ConfiguredArchitecture)
307307
@cfg_arch = arch
308308
end
309-
@arch = T.must(arch)
310-
@name = data["name"]
311-
@long_name = data["long_name"]
309+
@arch = T.must_because(arch) { pp data }
310+
@name = T.must_because(data["name"]) { pp data }
311+
@long_name = T.must_because(data["long_name"]) { pp data }
312+
@kind = T.must_because(data["kind"]) { pp data }
312313

313314
@sem = Concurrent::Semaphore.new(1)
314315
@cache = Concurrent::Hash.new

schemas/csr_schema.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
},
1818
"long_name": {
1919
"type": "string",
20-
"description": "Long name of the field",
21-
"pattern": ".*[^.!,]$"
20+
"description": "One line description of the CSR field"
2221
},
2322
"location": {
2423
"$ref": "schema_defs.json#/$defs/field_location",
@@ -216,8 +215,7 @@
216215
},
217216
"long_name": {
218217
"type": "string",
219-
"description": "Descriptive name for the CSR",
220-
"pattern": ".*[^.!,]$"
218+
"description": "One line description for the CSR"
221219
},
222220
"description": {
223221
"$ref": "schema_defs.json#/$defs/spec_text",

schemas/ext_schema.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@
9393
"name": { "$ref": "schema_defs.json#/$defs/extension_name" },
9494
"long_name": {
9595
"type": "string",
96-
"description": "One line description for the extension",
97-
"pattern": ".*[^.!,]$"
96+
"description": "One line description for the extension"
9897
},
9998
"description": {
10099
"$ref": "schema_defs.json#/$defs/spec_text",

schemas/inst_schema.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@
180180
},
181181
"long_name": {
182182
"type": "string",
183-
"description": "Short description of the instruction",
184-
"pattern": ".*[^.!,]$"
183+
"description": "One line description of the instruction"
185184
},
186185
"description": {
187186
"$ref": "schema_defs.json#/$defs/spec_text",

0 commit comments

Comments
 (0)