Skip to content

Commit 01c871b

Browse files
authored
Merge pull request #1329 from herbie-fp/codex/plan-removal-of-name-field-from-platform-struct
Remove name field from platform struct
2 parents 6d7af58 + 0feb07e commit 01c871b

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

src/syntax/platform.rkt

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(require racket/runtime-path)
44
(require "../utils/common.rkt"
55
"../utils/errors.rkt"
6+
"../config.rkt"
67
"../core/rules.rkt"
78
"matcher.rkt"
89
"types.rkt"
@@ -25,7 +26,6 @@
2526
;; Operator sets
2627
(contract-out ;; Platforms
2728
[platform? (-> any/c boolean?)]
28-
[platform-name (-> platform? any/c)]
2929
[platform-if-cost (-> platform? any/c)]
3030
[platform-reprs (-> platform? (listof representation?))]
3131
[platform-impls (-> platform? (listof symbol?))]
@@ -54,14 +54,12 @@
5454
;;;
5555
;;; A small API is provided for platforms for querying the supported
5656
;;; operators, operator implementations, and representation conversions.
57-
(struct platform (name [if-cost #:mutable] representations implementations representation-costs)
57+
(struct platform ([if-cost #:mutable] representations implementations representation-costs)
5858
#:name $platform
5959
#:constructor-name create-platform
6060
#:methods gen:custom-write
6161
[(define (write-proc p port mode)
62-
(if (platform-name p)
63-
(fprintf port "#<platform:~a>" (platform-name p))
64-
(fprintf port "#<platform>")))])
62+
(fprintf port "#<platform>"))])
6563

6664
;; Active platform
6765
(define *active-platform* (make-parameter #f))
@@ -72,11 +70,11 @@
7270
[representations (hash-copy (platform-representations platform))]
7371
[implementations (hash-copy (platform-implementations platform))]))
7472

75-
(define (make-empty-platform name)
73+
(define (make-empty-platform)
7674
(define reprs (make-hash))
7775
(define repr-costs (make-hash))
7876
(define impls (make-hash))
79-
(create-platform name #f reprs impls repr-costs))
77+
(create-platform #f reprs impls repr-costs))
8078

8179
(define (platform-register-if-cost! platform #:cost cost)
8280
(set-platform-if-cost! platform (platform/parse-if-cost cost)))
@@ -88,22 +86,22 @@
8886
(when (hash-has-key? reprs (representation-name repr))
8987
(raise-herbie-error "Duplicate representation ~a in platform ~a"
9088
(representation-name repr)
91-
(platform-name platform)))
89+
(*platform-name*)))
9290
; Update tables
9391
(hash-set! reprs (representation-name repr) repr)
9492
(hash-set! repr-costs (representation-name repr) cost))
9593

9694
(define (platform-register-implementation! platform impl)
9795
(unless impl
98-
(raise-herbie-error "Platform ~a missing implementation" (platform-name platform)))
96+
(raise-herbie-error "Platform ~a missing implementation" (*platform-name*)))
9997
; Reprs check
10098
(define reprs (platform-representations platform))
10199
(define otype (context-repr (operator-impl-ctx impl)))
102100
(define itype (context-var-reprs (operator-impl-ctx impl)))
103101
(define impl-reprs (map representation-name (remove-duplicates (cons otype itype))))
104102
(unless (andmap (curry hash-has-key? reprs) impl-reprs)
105103
(raise-herbie-error "Platform ~a missing representation of ~a implementation"
106-
(platform-name platform)
104+
(*platform-name*)
107105
(operator-impl-name impl)))
108106
; Cost check
109107
(define impl-cost (operator-impl-cost impl))
@@ -114,7 +112,7 @@
114112
(when (hash-has-key? impls (operator-impl-name impl))
115113
(raise-herbie-error "Impl ~a is already registered in platform ~a"
116114
(operator-impl-name impl)
117-
(platform-name platform)))
115+
(*platform-name*)))
118116
; Update table
119117
(hash-set! impls (operator-impl-name impl) impl))
120118

@@ -151,7 +149,7 @@
151149
(raise-herbie-error "Could not find support for ~a representation: ~a in a platform ~a"
152150
name
153151
(string-join (map ~s (hash-keys reprs)) ", ")
154-
(platform-name platform))))
152+
(*platform-name*))))
155153

156154
(define (repr-exists? name)
157155
(define platform (*active-platform*))
@@ -199,10 +197,7 @@
199197
(hash-ref impls
200198
impl-name
201199
(lambda ()
202-
(error 'impl-info
203-
"unknown impl '~a in platform ~a"
204-
impl-name
205-
(platform-name (*active-platform*))))))
200+
(error 'impl-info "unknown impl '~a in platform ~a" impl-name (*platform-name*)))))
206201
(case field
207202
[(name) (operator-impl-name impl)]
208203
[(vars) (context-vars (operator-impl-ctx impl))]
@@ -377,7 +372,7 @@
377372
(define repr-costs (platform-representation-costs platform))
378373
(define if-cost (platform-if-cost platform))
379374

380-
(printf "Platform: ~a;\n if-cost: ~a;\n\n" (platform-name platform) if-cost)
375+
(printf "Platform;\n if-cost: ~a;\n\n" if-cost)
381376

382377
(printf "Representations:\n")
383378
(define reprs-data

src/syntax/platforms-language.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
(with-syntax ([local-platform (datum->syntax stx 'platform)])
4343
(syntax-case stx ()
4444
[(_ content ...)
45-
#'(#%module-begin (define local-platform (make-empty-platform 'platform))
45+
#'(#%module-begin (define local-platform (make-empty-platform))
4646
(define old-platform-being-defined (platform-being-defined))
4747
(platform-being-defined local-platform)
4848
content ...

0 commit comments

Comments
 (0)