From 0d00b872c31801232407378722fec84850811890 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:02:06 +0000 Subject: [PATCH 1/3] Initial plan From a7ee08fe3630f6047e463c65c20e1dba25121499 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:15:47 +0000 Subject: [PATCH 2/3] Add refactoring rule to suggest hash instead of make-immutable-hash with quasiquote Co-authored-by: jackfirth <8175575+jackfirth@users.noreply.github.com> --- .../hash-shortcuts-test.rkt | 60 +++++++++++++++++++ default-recommendations/hash-shortcuts.rkt | 20 +++++++ 2 files changed, 80 insertions(+) diff --git a/default-recommendations/hash-shortcuts-test.rkt b/default-recommendations/hash-shortcuts-test.rkt index bdefad27..40eab788 100644 --- a/default-recommendations/hash-shortcuts-test.rkt +++ b/default-recommendations/hash-shortcuts-test.rkt @@ -295,3 +295,63 @@ no-change-test: (define sum (hash-ref! h1 (cadr term) 0)) (hash-set! h2 (cadr term) (+ (car term) sum))) ------------------------------ + + +test: "make-immutable-hash with quasiquoted pairs can be simplified to hash" +------------------------------ +(define body 'test-body) +(define event 'test-event) +(define comments '(c1 c2)) +(make-immutable-hash + `((body . ,body) + (event . ,event) + (comments . ,(map values comments)))) +============================== +(define body 'test-body) +(define event 'test-event) +(define comments '(c1 c2)) +(hash 'body body 'event event 'comments (map values comments)) +------------------------------ + + +test: "make-immutable-hash with simple quasiquoted pairs can be simplified to hash" +------------------------------ +(define x 1) +(define y 2) +(make-immutable-hash `((a . ,x) (b . ,y))) +============================== +(define x 1) +(define y 2) +(hash 'a x 'b y) +------------------------------ + + +test: "make-immutable-hash with single pair can be simplified to hash" +------------------------------ +(define value 42) +(make-immutable-hash `((key . ,value))) +============================== +(define value 42) +(hash 'key value) +------------------------------ + + +no-change-test: "make-immutable-hash without quasiquote should not be changed" +------------------------------ +(make-immutable-hash '((a . 1) (b . 2))) +------------------------------ + + +no-change-test: "make-immutable-hash with variable keys should not be changed" +------------------------------ +(define k 'key) +(define v 'value) +(make-immutable-hash `((,k . ,v))) +------------------------------ + + +no-change-test: "make-immutable-hash with list literal should not be changed" +------------------------------ +(define pairs '((a . 1) (b . 2))) +(make-immutable-hash pairs) +------------------------------ diff --git a/default-recommendations/hash-shortcuts.rkt b/default-recommendations/hash-shortcuts.rkt index 797669e4..a33032f0 100644 --- a/default-recommendations/hash-shortcuts.rkt +++ b/default-recommendations/hash-shortcuts.rkt @@ -159,6 +159,25 @@ (hash-values h)) +(define-syntax-class quoted-key + #:attributes (key) + #:literals (quote) + (pattern (quote key:id))) + + +(define-syntax-class hash-pair-with-quoted-key + #:attributes (key value) + #:literals (unquote) + (pattern (key:id unquote value))) + + +(define-refactoring-rule make-immutable-hash-with-quasiquote-to-hash + #:description "This `make-immutable-hash` with quasiquoted pairs can be replaced with a simpler `hash` call." + #:literals (make-immutable-hash quasiquote) + (make-immutable-hash (quasiquote (pair:hash-pair-with-quoted-key ...))) + (hash (~@ 'pair.key pair.value) ...)) + + (define-refactoring-suite hash-shortcuts #:rules (define-hash-ref-set!-to-hash-update! hash-map-to-hash-keys @@ -169,4 +188,5 @@ hash-ref-with-constant-lambda-to-hash-ref-without-lambda hash-ref!-with-constant-lambda-to-hash-ref!-without-lambda hash-set!-ref-to-hash-update! + make-immutable-hash-with-quasiquote-to-hash or-hash-ref-set!-to-hash-ref!)) From 9531faadbe8a55e8ab5fdd95297a748305655395 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:17:29 +0000 Subject: [PATCH 3/3] Remove unused quoted-key syntax class Co-authored-by: jackfirth <8175575+jackfirth@users.noreply.github.com> --- default-recommendations/hash-shortcuts.rkt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/default-recommendations/hash-shortcuts.rkt b/default-recommendations/hash-shortcuts.rkt index a33032f0..eea2e8e9 100644 --- a/default-recommendations/hash-shortcuts.rkt +++ b/default-recommendations/hash-shortcuts.rkt @@ -159,12 +159,6 @@ (hash-values h)) -(define-syntax-class quoted-key - #:attributes (key) - #:literals (quote) - (pattern (quote key:id))) - - (define-syntax-class hash-pair-with-quoted-key #:attributes (key value) #:literals (unquote)