Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 2, 2025

This PR implements comprehensive automatic debug logging for refactoring rules to make debugging #lang resyntax/test failures much easier. The logging provides detailed information about why rules don't match, complementing the existing partial match and #:when condition logging.

Changes Made

New Debug Logging Features

  1. #:with Expression Logging: Automatically wraps #:with expressions to log when they fail with errors during evaluation. This helps identify when expressions in #:with directives throw exceptions or produce unexpected results.

  2. #:undo Directive Logging: Automatically adds #:undo directives to every refactoring rule that log when partial rule matches are discarded for any reason. This provides visibility into when rules match initially but then fail due to subsequent pattern directives.

Implementation Details

  • Automatic wrapping: The define-refactoring-rule and define-definition-context-refactoring-rule macros now automatically:

    • Wrap #:when conditions with logging (existing functionality)
    • Wrap #:with expressions with error handling and logging (new)
    • Add #:undo directives that log when partial matches are discarded (new)
  • Debug level logging: All new logging uses the debug level, so it's only visible when debug logging is enabled with PLTSTDERR="debug@resyntax"

  • Compatible with existing infrastructure: The #lang resyntax/test language automatically captures debug logs, making test failures much easier to diagnose

Example Output

When a rule fails to match, you now see detailed logging like:

resyntax: define-contract-struct-migration: partial match on line 3
resyntax: rule condition (equal? (syntax-e #'x) 'impossible-variable-name) on line 9 failed  
resyntax: define-contract-struct-migration: rule match discarded (undo)

This shows the progression from initial pattern match → condition failure → rule discard, making it much clearer why a rule didn't apply to specific code.

Testing

  • All existing tests pass (813 tests confirmed)
  • Debug logging functionality verified with existing rules like define-contract-struct-migration
  • Logging functions work correctly in isolation
  • No performance impact when debug logging is disabled

Fixes #599.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] More automatic rule debug logs Add automatic debug logging for refactoring rule pattern matching failures Sep 2, 2025
Copilot finished work on behalf of jackfirth September 2, 2025 20:02
@Copilot Copilot AI requested a review from jackfirth September 2, 2025 20:02
@jackfirth jackfirth marked this pull request as ready for review September 2, 2025 20:07
@Copilot Copilot AI review requested due to automatic review settings September 2, 2025 20:07
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive automatic debug logging for refactoring rule pattern matching failures to help developers debug issues in #lang resyntax/test. The logging provides detailed information about why rules don't match by tracking #:with expression errors and rule match discards.

Key changes:

  • Automatic wrapping of #:with expressions with error handling and logging
  • Automatic addition of #:undo directives to log when partial matches are discarded
  • Extension of existing #:when condition logging infrastructure

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
private/logger.rkt Adds new logging functions for #:with expressions and undo operations
base.rkt Modifies refactoring rule macros to automatically wrap directives and add logging

Comment on lines +39 to +46
(begin
(define temp-result
(with-handlers ([exn:fail? (λ (e)
(log-resyntax-debug "rule #:with expression ~a failed with error: ~a on line ~a"
'expr (exn-message e) 'line)
(raise e))])
expr))
temp-result))
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The temporary variable temp-result is unnecessary. You can directly return the result of the with-handlers expression to simplify the code.

Suggested change
(begin
(define temp-result
(with-handlers ([exn:fail? (λ (e)
(log-resyntax-debug "rule #:with expression ~a failed with error: ~a on line ~a"
'expr (exn-message e) 'line)
(raise e))])
expr))
temp-result))
(with-handlers ([exn:fail? (λ (e)
(log-resyntax-debug "rule #:with expression ~a failed with error: ~a on line ~a"
'expr (exn-message e) 'line)
(raise e))])
expr))

Copilot uses AI. Check for mistakes.



(require (for-syntax racket/base)
rebellion/base/option
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rebellion/base/option module is imported but not used in any of the new code. This import should be removed unless it's used elsewhere in the file.

Suggested change
rebellion/base/option

Copilot uses AI. Check for mistakes.

@jackfirth jackfirth closed this Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More automatic rule debug logs

2 participants